alnouirah's avatar

upload files ?

Hello guys . i get confused in how to store file and retrieve it inside the view . when uploading file for example image i do :

$path = $products->store('public/customer_order_products'); 

the value of the $path will be public\customer_order_products\uVPXIMwCeRiI6XBIyhTg.jpg . right know how to retrieve the image inside view ? i used {{ asset('storage\') }}{{ $path }} but it doesn't work i also used url() even Storage::($file)` and nothing work ! is there any one who can help me to understand how the things work here ! i have read the doc but i get confused !

0 likes
6 replies
alnouirah's avatar

@jlrdw & @martinbean just for make it clear , i have read the docs and it says:

In web applications, one of the most common use-cases for storing files is storing user uploaded files such as profile pictures, photos, and documents. Laravel makes it very easy to store uploaded files using the store method on an uploaded file instance.

so , i used store method like that :

$path = $products->store('public/customer_order_products'); 

and i specified public folder because i want the file to be publicly accessible . so asset method give me the absolute path : http://127.0.0.1:8000/storage/public/customer_order_products/iNUEpTwIekpcibPoSHk2cnYRSje3jEEpliYC7HAN.jpeg

and that path not working ! it only works without public like the following : http://127.0.0.1:8000/storage/customer_order_products/iNUEpTwIekpcibPoSHk2cnYRSje3jEEpliYC7HAN.jpeg and to make it like that i used :

{{ url('/') }}{{ Storage::url($product->product) }}

it solve the problem but i didn't understand how the things work ! or even what Storage is or how to use it ! . i get confused after reading the docs so i asked here . BTW thanks for your help .

alnouirah's avatar

Yes , and it's pointing to storage/app/public/ folder .

mix5003's avatar

i think it because you use default local as filesystem driver. if you want file to public and store as local file system, i think you should set public to default file driver. or you may specific disk name when you store file like this.

$path = $products->store('customer_order_products', /* disk name */ 'public'); 
// or in fullform
$path = $products->store('customer_order_products', ['disk' => 'public']);

Please or to participate in this conversation.