jeremihza's avatar

Hello I want to upload image on my laravel project , so when I submit the request I get error message under the image

i added in index.php $app->bind('path.public', function() { return DIR; }); but no change

0 likes
5 replies
Snapey's avatar

sorry but your question is not clear, and what you posted as code does not seem to be related to your question

1 like
milosradic's avatar

Maybe you can do something like this.

In console execute:

php artisan storage:link

This will make shortcut to your storage inside your public folder.

After that you can move uploaded image using: note*: i assume your input type file has name "image" and don't forget to add enctype="multipart/form-data" to your form so upload is working

$request->image->storeAs('public/uploads', $filename);

note*: this will move your uploaded file to storage/app/public/uploads/ and will create this public/uploads if it doesn't exist

When you want to show the image on your view you can do it like this:

<img src="{{ asset('storage/uploads/'.$yourItem->image) }}">

I assume you save your full image name in database in column image and have that row from database available on view.

milosradic's avatar

I didn't explain how you can generate $filename. Example

$filename = "image.jpg";

or

$filename = str_slug($request->title).'.'.$request->image->getClientOriginalExtension();

or

$filename = 'image.'.$request->image->getClientOriginalExtension();
ajithlal's avatar

Sorry your question is not clear. I think you forget to include the enctype on form tag. Please add enctype="multipart/form-data" in your form tag.

Hope this will help.

Please or to participate in this conversation.