0 レビュー
3 回答
php-laravelで製品ページを検索するためにページ付けを追加する方法
ショーコントローラーを使用して、検索する商品アイテムビューにページネーションを追加したい
これは私のコントローラーです
public function show($id)
{
$categories = Item::all();
$products = Item::find($id)->products->paginate(3);
return view('category.index', compact('categories', 'products'));
}
これは私の見解です
@extends('layout.front')
@section('page')
<div class="row" id="portfolio">
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col-lg-3" style="margin-top:20px;">
<nav class="main-nav">
<ul class="main-nav-ul">
<li style="background-color: #343A40; color: #ffffff; font-weight: 600;" id="sidebar-header"><a>Product List</a></li>
<li><a href="{{ url('/computer') }}" style="font-weight: 600;">Computer<span></span></a>
<ul>
@if(!empty($categories))
@forelse($categories as $category)
<li><a href="{{ route('category.show', $category->id)}}">{{ $category->name }}</a></li>
@empty
<li>No data found</li>
@endforelse
@endif
</ul>
</li>
<li><a href="#" style="font-weight: 600;">CCTV</a></li>
<li><a href="#" style="font-weight: 600;">Gaming</a></li>
</ul>
</nav>
</div>
<!-- /.col-lg-3 -->
<div class="col-lg-9">
<div class="row" style="margin-top:20px;">
@if(!empty($products))
@foreach($products as $key=>$product)
<div class="col-md-4 col-sm-6 portfolio-item" id="items">
<div class="card h-100">
<a href="#"><img class="card-img-top" src="/storage/{{ $product->image }}" alt="Product Image"></a>
<div class="card-body">
<h4 class="card-title">
<a href="#">{{ $product->category_name }}<br />{{ $product->item_name}}</a>
</h4>
<p class="card-text" style="color: #A9A9A9;text-decoration: line-through;">LKR {{ $product->old_price}}</p>
<h4 style="text-align: center; color: #fff;"><a class="waves-effect waves-light btn btn-dark btn-block">LKR {{ $product->new_price}}</a></h4>
{{[email protected]}}
</div>
</div>
</div>
@endforeach
@endif
</div>
<!-- /.row -->
</div>
<!-- /.col-lg-9 -->
</div>
<!-- /.row -->
</div>
<!-- /.container -->
</div>
<div class="col-lg-12">{!! $products->links() !!}</div>
@endsection
laravelのデフォルトのページ付けを使用し、ブートストラップのページ付けをlaravelにカスタマイズしました。
しかし、コントローラーのページネーションのショー機能が機能していません。検索製品のページネーションを修正する方法。
リンク方式を使用しました。ただし、このビューでは機能しません。
<div class="col-lg-12">{!! $comproducts->links() !!}</div>
わからない
0
レビュー
答え :
解決策:
コードのどこにもページネーションを使用していません。ページネーションを追加する方法については、ドキュメントを確認してください。 db呼び出しを行うときは、 paginate
関数を使用してから、paginatorリンクを使用する必要があります。
わからない
0
レビュー
答え :
解決策:
こんにちはここでページネーションコードを見つけてください
Table:stocks PK:id、Varchar:name
StockController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\LengthAwarePaginator;
use App\Http\Controllers\Controller as Controller;
class StockController extends Controller {
public function usaPage() {
$stocks = DB::table('stocks')->orderBy('name', 'ASC')->paginate(50);
return view('stock.usa', ['stocks' => $stocks]);
}
?>
usa.blade.php
@section('content')
<div class="row">
<div class="col-md-12">
<table class="table">
<tr>
<th scope="col">Company Name</th>
<th scope="col">ID</th>
</tr>
@foreach ($stocks as $stock)
<tr><td> {{ $stock->name }}</a></td><td> {{ $stock->id }}</td></tr>
@endforeach
</table>
</div>
</div>
@endsection
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。