Vivek Titwal Vivek Titwal - 4 months ago 9
PHP Question

How to get an image on the desired page by clicking on that image using Laravel?

I am working on the laravel 5.0. I am getting an error: "trying to get property of non-object".I want to get an image on the desired page by clicking on that particular image. There are so many images on the page, i just want after clicking on any image, it will be appear on the desired page.
here is my code:

My Routes:

Route::get('/image/big/{id}' ,[
'uses'=>'GalleryController@bigimage',
'as'=>'bigimage'
]);


My controller:

public function bigimage($id){

$images=image::findorFail($id);
return view('bigimage' , ['images'=>$images]);
}


My view from where i am calling the required Route:

@foreach($gallery->images as $image)
<li>
<a href="{{ URL('/image/big/'.$image->id) }}">
<img id="jumboimage2" src="{{ url($image->file_path) }}"></a>
</li>
<li>
<a href="{{ URL('/image/delete/'.$image->id) }}" id="margin">
<span id="margin" class="glyphicon glyphicon-remove-sign"></span></a>
</li>
@endforeach


My view where i want to get the required image:

<div class="row">
<section class="col-md-3">
@foreach($images as $image)
{{$image->id}}
@endforeach
</section>
</div>

Answer
try this one out



$image = image::findOrFail($id);


return view('bigimage' , ['image' => $image])
Comments