<img class="card-img" src="{{Storage::url($project->image_name)}}" />
May 9, 2022
9
Level 1
linking /public and /storage doesn't work
Hello, I have a form where i can upload an image. The image successfully uploads to storage/app/public/img I want to display it in the view and that doesn't work even though i did "php artisan storage:link". Is it not linked properly or did i do something else wrong? Thanks.
The store() method in the controller:
public function store(Request $request) {
$title = $request->input('title');
$summary = $request->input('summary');
$description = $request->input('description');
$path = $request->file('image')->store('public/img');
$project = new Project;
$project->title = $title;
$project->summary = $summary;
$project->description = $description;
$project->image_name = $path;
$project->save();
return redirect('/projecten');
}
The view with the image
@foreach ($projects as $project)
//
<img class="card-img" src="{{asset('storage/'.$project->image_name )}}" />
@endforeach
The view with image in the browser:
<img class="card-img" src="http://homestead.test/storage/public/img/2v1pbmXPd9Zsh74UE7DB3ReQ8pHH0ueDEwXrZlBR.png">
config/filesystems.php:
'links' => [
public_path('storage/img') => storage_path('app/public/img')
],
Please or to participate in this conversation.
