John Davidson

php - problem while trying to display image from database

0 comments
Message:


I am trying to display a row from my database by id, the data displayed successfully but the image doesn't show (showing a broken link icon).


Here is the index.blade.php where the href to the row:


<a href="singlepost/{{$products->id}}">
<img src="storage/{{$templates->image_path2}}">

The route:


Route::get('/singlepost/{id}', 'App\http\controllers\TemplatesController@getPostById')->name('single.post');

The function getPostById


public function getPostById($id){
$products = DB::table('templates')->where('id', $id)->first();

return view('singlepost', compact('products'));
}

The singlepage.blade.php


<div class="row">
<div class="col-lg-4">
<img src="storage/{{$products->image_path}}">
</div>
<div class="col-lg-7">
<h2>{{$products->name}}</h2>
<p>{{$products->description}}</p>
</div>
</div>


My Answer:
php
@foreach($rows as $row)

{{ $row->title }}


{{ $row->description }}


Image

@endforeach


Make sure that the image path in the database is correct and that the image file exists in the storage directory. Also, check the file permissions of the storage directory to ensure that the web server has access to it.

Rate this post

3 of 5 based on 7294 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us