in staging server run artisan command
php artisan storage:link
Image URL works in local serve but fails in staging environment
Hi guys, 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://stagingurl/storage/images/products/staging_testprod_13.jpeg"
}
Very sorry guys. I forgot to copy the storage folder from public to public_html when I made updates and had to copy the entire app again to the staging server.
Please or to participate in this conversation.