0
votes

i'm newbie in laravel

I'm just succesfully upload an image and store name in database. linkd 'public' folder to 'storage/App/public' also but can't show it on the page. image is also on that folder with protected random name. I can't load image with that url also 'http://localhost:8000/storage/flower.jpg'. what should i do now ????

web.php

Auth::routes();
Route::post('/update/{id}','HomeController@update')->name('update');
Route::get('/home', 'HomeController@index')->name('home');

HomeContoller.php

public function update(Request $request,$id){

       $student = user::find($id);

       if ($file = $request->file('profile_image')) {
           $file = $request->file('profile_image');
           $request->file('profile_image')->store('public/');
           $img_nm = $file->getClientOriginalName();
           $request->file('profile_image')->getClientOriginalName();

           $student->image = $img_nm;
       }

         $student->username = $request ->username;
         $student->first_name = $request ->first_name;
         $student->last_name = $request ->last_name;
         $student->gender = $request ->gender;
         $student->email = $request ->email;
         $student -> save();
         return redirect()->route('home');

 }

home.blade.php

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

fileSystems.php

'default' => env('FILESYSTEM_DRIVER', 'local'),

'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],
2
Can you show more of your code?MH304
sir I have updated my code. Please help me out. If need more ask me. Thanksmohammad said
"linkd 'public' folder to 'storage/App/public'" Are you using symlinks? Note that to use links - you need Options Indexes FollowSymLinks for your project <Directory> in your apache site config.Vinay

2 Answers

0
votes

you can try this

<img src="storage/"{{$student-> image}}/>
0
votes

The upload method is wrong, if the original filename is needed then, use the storeAs function,

$file = $request->file('profile_image');

$img_nm = $file->getClientOriginalName();
$file->storeAs('images', $img_nm);
$student->image = $img_nm;

Refer https://laravel.com/docs/6.x/filesystem#file-uploads

And in your blade file, use this

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

Hope this helps.