Verluro's avatar

Upload file

Hello, I started to learn Laravel and I have a problem. I want to upload image (name -> database), (file -> storage/app/images/product/filename.ext)

I have code to upload file:

$file = $request->file; $name = $request->file->getClientOriginalName();

$path = "images/product/"; $fileName = time().'-'.$name; Storage::disk('local')->put($path.$fileName, file_get_contents($file));

I want to get file path (filename from database) in product.blade.php

What code should I enter to get path? I try:

storage/app/images/product/{{ $data->image }}

Regards, Verluro

0 likes
1 reply
jlrdw's avatar

Do you realize How to upload image is asked here once or twice a week at least.

Many have shown examples.

Would you at least attempt a search on forum for this topic first.

And enclose code between 3 backticks before and after.

To display I usually

<img src="<?= asset('assets/upload/imgdogs') . '/' . $row->dogpic; ?>" alt="" class="image">

I don't use blade so just use blade as needed. Remember to store is file system, to display is url. See helpers in docs.

Please or to participate in this conversation.