Anyone here know about pagination with post method in laravel? Here's my code my pagination didn't work properly can anybody help me with this? It shows first page data when i move to next page it shows the empty render...I tried it through ajax with post method coz i need fiter data with pagination...
Blade:
@extends('layouts.app')
@section('content')
<div id="html_code" class="col-sm-6 col-lg-12" style="margin-bottom:20px; background-color:#047137">
<table>
<tr><th>Name</th>
<th>Email</th></tr>
@foreach($get_data as $data)
<tr><td></td>
<td></td></tr>
@endforeach
</table>
</div>
<div>
{!!$get_data->links()!!}
</div>
<script>
$(document).ready(function(){
$(document).on('click', '.pagination a', function(event){
event.preventDefault();
var page = $(this).attr('href').split('page=')[1];
fetch_data(page);
});
function fetch_data(page)
{$.ajax({
url:"/pagination/fetch_data?page="+page,
success:function(data)
{$('#html_code').html(data);}
});
}
});
</script>
@endsection
Controller:
public function users(Request $request)
{
$category = $request->category;
$get_data = User::where('category',$category)->paginate(20);
return view('data',compact('get_data'));
}
function fetch_data(Request $request)
{
$category = $request->category;
if($request->ajax())
{
$get_data = User::where('category',$category)->paginate(20);
return view('data',compact('get_data'))->render();
}
}
Routes:
Route::match(['get', 'post'], 'monthly_report', ['uses'=>'HomeController@users']);
Route::get('pagination/fetch_data', 'HomeController@fetch_data');
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire