Apr 13, 2015
0
Level 1
Keep pagination after action
Hello,
I have a functionnal pagination. But i have a tab with lines and buttons and when i click on this button ( this button was link to other action in controller), i go to the first page of my pagination.
for exemple i am on the 4 pagination page and when i click on this button, this function was achieve and after this i was redirect on the 1rst page of the pagination...
How to be redirected on the same page ? i think i need use session and i have the number of the page, but how use it ??
My action is :
public function activate($id) {
$valActiver = \App\Models\Point::find($id);
if ($valActiver->active == 1) {
$test = \DB::table('Point')
->where('pointID', $id)
->update(array('active' => '0', 'updated_at' => date('Y-m-d H:i:s')));
} else {
$test = \DB::table('Point')
->where('pointID', $id)
->update(array('active' => '1', 'updated_at' => date('Y-m-d H:i:s')));
}
$page = \Session::all();
$urlPrec = $page['_previous']['url'];
$monNumPage = parse_url($urlPrec);
if(array_key_exists('query',$monNumPage)){
$monNumPage = str_replace('page=', '', $monNumPage['query']);
}
return \Redirect::action('DotsController@index');
}
public function index() {
$titre = "Dots";
$titreinfos = DotsController::TITREINFOS;
$infos = DotsController::INFOS;
$plansChoix = \DB::table('Plan')->lists('name', 'planID');
$points = \DB::table('Point')
->leftjoin('Network', 'Network.networkID', '=', 'Point.networkID')
->leftjoin('TPoint', 'TPoint.tpointID', '=', 'Point.tpointID')
->orderBy('Point.pointID', 'asc')
->paginate(30, array('Point.pointID', 'Point.active', 'Point.name', 'Network.label as netlab', 'TPoint.label as tplab'));
$networks = \DB::table('Network')->lists('label', 'networkID');
$types = \DB::table('TPoint')->lists('label', 'tpointID');
return view('networkDots', compact('points', 'networks', 'types', 'titre', 'infos', 'titreinfos', 'plansChoix'));
}
And in my routes.php
Route::get('dots/{id}', 'DotsController@activate');
Route::get('dots', 'DotsController@index');
Route::get('dotsFilter', 'DotsController@filter');
And this is a part of my view :
<table class="table table-striped mon-tab-avec-photo">
<thead>
<tr>
<th class="noMobile">#</th>
<th>Name</th>
<th class="noMobile">Network</th>
<th class="noMobile">Type of path</th>
<th class="noMobile">Activated</th>
<th>Infos</th>
</tr>
</thead>
<tbody>
@foreach($points as $point)
<tr>
<td class="zonePourLaCouleur noMobile">{{ $point->pointID }}</td>
<td class="zonePourLaCouleurMobile">{{ $point->name }}</td>
<td class="noMobile">{{ $point->netlab }}</td>
<td class="noMobile">{{ $point->tplab }}</td>
<td class="noMobile">
@if($point->active == 0)
{!! HTML::linkAction('DotsController@activate', 'Activer', array($point->pointID), array('class' => 'buttonActiveDesa')) !!}
@else
{!! HTML::linkAction('DotsController@activate', 'Desactiver', array($point->pointID), array('class' => 'buttonActive')) !!}
@endif
</td>
<td>{!! HTML::linkAction('DotsController@infos', ' ', array($point->pointID), array('class' => 'buttonEdit')) !!}</td>
</tr>
@endforeach
</tbody>
</table>
{!! str_replace('/?', '?', $points->render()) !!}
Thank
Please or to participate in this conversation.