Pagination not working links displaying fine.
when I clicked on 2nd-page same 1st-page items only showing even, clicked on any page first results only showing but url changing as per the click results of items not changing.
Please check the below code controller and view file code given below.
Controller:
public function index(Request $request)
{
$keyword = $request->get('search');
$perPage = 10;
if (!empty($keyword)) {
$products = Product::where('pname', 'LIKE', "%$keyword%")
->orWhere('pdescription', 'LIKE', "%$keyword%")
->orWhere('price', 'LIKE', "%$keyword%")
->orWhere('pcategory', 'LIKE', "%$keyword%")
->orWhere('brandname', 'LIKE', "%$keyword%")
->orWhere('pcategoryslug', 'LIKE', "%$keyword%")
->orWhere('productslug', 'LIKE', "%$keyword%")
->orWhere('pimg', 'LIKE', "%$keyword%")
->orWhere('pimg1', 'LIKE', "%$keyword%")
->orWhere('pimg2', 'LIKE', "%$keyword%")
->orWhere('pimg3', 'LIKE', "%$keyword%")
->orWhere('pimg4', 'LIKE', "%$keyword%")
->orWhere('pimg5', 'LIKE', "%$keyword%")
->orWhere('partner_id', 'LIKE', "%$keyword%")
->orWhere('status', 'LIKE', "%$keyword%")
->paginate($perPage);
} else {
$products = Product::where(['partner_id'=>\App\Partner::id()])->orderBy('id','desc')->paginate(10);
// $products = DB::table('products')->select('products.id as id','pname','pdescription','path','pcategory','price')->where(['products.partner_id'=>\App\Partner::id()])->join('product_images', 'product_images.product_id', '=', 'product_images.product_id')->groupBy('product_images.product_id')->paginate($perPage);//toSql(); //p
}
return view('admin.products.index',['products'=>$products]);
}
view:
<div class="table-responsive">
<table class="table table-borderless">
<thead>
<tr>
<th>ID</th><th>Image</th><th>Name</th><th>Description</th><th>Category</th><th>Price</th><th>Actions</th>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
@foreach($products as $item)
<tr>
<td><?= $i++; ?></td>
<td><img src="" width="50" /></td>
<td></td>
<td></td>
<td></td>
<td>Rs </td>
<td>
<a href="" title="View Product"><button class="btn btn-info btn-xs"><i class="fa fa-eye" aria-hidden="true"></i> View</button></a>
<a href="" title="Edit Product"><button class="btn btn-primary btn-xs"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit</button></a>
{!! Form::open([
'method'=>'DELETE',
'url' => ['/admin/products', $item->id],
'style' => 'display:inline'
]) !!}
{!! Form::button('<i class="fa fa-trash-o" aria-hidden="true"></i> Delete', array(
'type' => 'submit',
'class' => 'btn btn-danger btn-xs',
'title' => 'Delete Product',
'onclick'=>'return confirm("Confirm delete?")'
)) !!}
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="pagination-wrapper"> {!! $products->appends(['search' => Request::get('search')])->render() !!} </div>
{!! $products->render() !!}
</div>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire