John Davidson

php - problem while trying to display image from database


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('');

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 class="col-lg-7">

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

{{ $row->title }}

{{ $row->description }}



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

4 of 5 based on 5745 votes


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