Vivek Titwal Vivek Titwal - 4 months ago 8
PHP Question

How to Route back with passing parameters using Laravel?

I am working on Laravel 5.0. I want to return back from my current page to the previous page with passing parameter. I have an id of all images and galleries in my urls. After clicking on a particular image, i move to another page with the id of that image in my url, Now, i want to return back to my gallery page to which that image belongs to.

My controller:

public function viewgallerypics($id){
$gallery= Gallery::findorFail($id);
return view('dropzone' , ['gallery'=>$gallery]);
}

public function bigimage($id){
$gallery=Gallery::all();
$image=image::findorFail($id);
return view('bigimage' , ['image'=>$image,'gallery'=>$gallery]);

}


My routes:

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


Route::get('/gallery/view/{id}' ,[
'uses'=>'GalleryController@viewgallerypics',
'as'=>'viewpics'
]);


My view:

<section class="col-md-1">
<a class="btn btn-primary btn-lg"
href="HERE, WHAT I HAVE TO PASS TO GET MY DESIRED
PAGE????">Back</a>
</section>


My desired page where i want to return back depending on the id pass through the route:

<div class="row">
<div class="col-md-offset-1 col-md-10">
<div id="gallery-images">
<ul>
@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
</ul>
</div>
</div>
</div>

Answer

use {{ URL::previous() }}

<section class="col-md-1">
    <a class="btn btn-primary btn-lg" href="{{ URL::previous() }}">Back</a>
</section>
Comments