Reputation: 2029
I am working on an API application using Laravel 5.8 version. When a get request is made to the products
api endpoint, I return a ProductResource
collection which looks like this
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'category' => $this->category,
'description' => $this->description,
'status' => $this->status,
'price' => $this->price,
'barrels' => $this->barrels,
'interest' => $this->interest,
'start' => $this->start,
'end' => $this->end,
'hidden' => $this->hidden,
'imageUrl' => asset('storage/images/products/' . $this->image->name)
];
}
The challenge I am having is that on my local server clicking the returned imageUrl
displays the correct image but in the staging environment, I get the default 404
not found page.
I created a symbolic link from public/storage
to storage/app/public
on my local server which i am developing on to store the actual image file before uploading the app file to the staging environment. A quick check of the storage/app/public/images/products
in the staging environment shows the image file but I still cannot view it from my browser. What could be the possible reason for this behavior?
Here's a sample of the resource in both my local and staging environments
Local/development server
{
"id": 17,
"name": "test",
"category": "test",
"description": "test",
"status": "test",
"price": 10990,
"barrels": 207736,
"interest": 0.2,
"start": "2019-07-25",
"end": "2019-08-25",
"hidden": 0,
"imageUrl": "http://localhost:8000/storage/images/products/pramopro_test_17.jpeg"
}
Staging server
{
"id": 13,
"name": "test prod",
"category": "test prod category",
"description": "test prod description",
"status": "loading",
"price": 10000,
"barrels": 300000,
"interest": 0.2,
"start": "2019-07-22",
"end": "2019-08-28",
"hidden": 0,
"imageUrl": "http://staging.pramopro.com/storage/images/products/pramopro_testprod_13.jpeg"
}
Upvotes: 0
Views: 292
Reputation: 1353
you need to make symlink to your storage folder like this:
ln -s ../project/storage/app/public storage
you will run it into your website files not into public_html
folder
Upvotes: 1
Reputation: 2029
So the issue was caused because I forgot to copy the public/storage
folder to public_html
when I copied a fresh copy of the app from my development server to the host VPS.
Upvotes: 0