gpt4 book ai didi

php - 通过 Blade 分页传递变量

转载 作者:行者123 更新时间:2023-12-05 06:08:47 25 4
gpt4 key购买 nike

我需要在 laravel blade 上使用分页,但是从 Controller 传来另一个不通过分页的变量,我该如何解决?

<div class="main-content">
<div class="breadcrumb">
<h1>Página de Cliente</h1>
</div>
<div class="separator-breadcrumb border-top"></div>
<div class="card user-profile o-hidden mb-4">

<div class="user-info"><img class="profile-picture avatar-lg mb-2" alt="" />
<p class="m-0 text-24">{{ $customer->name }}</p>
<p class="text-muted m-0">{{ $customer->email }}</p>
</div>
<div class="card-body">
<ul class="nav nav-tabs profile-nav mb-4" id="profileTab" role="tablist">
<li class="nav-item"><a class="nav-link active" id="timeline-tab" data-toggle="tab" href="#timeline" role="tab" aria-controls="timeline" aria-selected="false">Propostas</a></li>
<li class="nav-item"><a class="nav-link" id="about-tab" data-toggle="tab" href="#about" role="tab" aria-controls="about" aria-selected="true">#</a></li>
<li class="nav-item"><a class="nav-link" id="friends-tab" data-toggle="tab" href="#friends" role="tab" aria-controls="friends" aria-selected="false">#</a></li>
<li class="nav-item"><a class="nav-link" id="photos-tab" data-toggle="tab" href="#photos" role="tab" aria-controls="photos" aria-selected="false">#</a></li>
</ul>
<div class="tab-content" id="profileTabContent">
<div class="tab-pane fade active show" id="timeline" role="tabpanel" aria-labelledby="timeline-tab">
<div class="row mb-4">
<div class="col-md-12 mb-3">
<div class="card text-left">
<div class="card-body">
<h4 class="card-title mb-3">Lista de Propostas</h4>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Data</th>
<th scope="col">Vendedor</th>
<th scope="col">Produto</th>
<th scope="col">Preço</th>
<th scope="col">Produção</th>
</tr>
</thead>
@foreach($proposals as $proposal)
<tbody>
<tr>
<th scope="row"> {{ $proposal->id_proposal }} </th>
<td> {{ $proposal->date }} </td>
<td> {{$proposal->users()->first()->name }} </td>


<td>
@foreach($proposal->proposed_phases()->get() as $proposedphase)
<p>{{ $proposedphase->features()->first()->name }}</p>
@endforeach
</td>
<td>
@foreach($proposal->proposed_phases()->get() as $proposedphase)
<p>{{ $proposedphase->amount }}€</p>
@endforeach
</td>

@if($proposal->id_production == null)
<td><span class="badge badge-danger">Produção</span></td>
@else
<td><span class="badge badge-success">Produção</span></td>
@endif

@if($proposal->id_production == null)
<td>
<a href="{{ URL::route('new.production', array('id_proposal'=>$proposal->id_proposal)) }}" class="text-success mr-2">
<button class="nav-icon i-Add font-weight-bold btn btn-success m-0" type="button" data-toggle="tooltip" data-placement="top" title="Criar Produção"></button>
</a>
</td>
@else
<td>
<a href="{{ URL::route('new.label', array('id_proposal'=>$proposal->id_proposal)) }}" class="text-success mr-2">
<button class="nav-icon i-Add font-weight-bold btn btn-warning m-0" type="button" data-toggle="tooltip" data-placement="top" title="Criar Etiquetas"></button>
</a>
</td>
@endif
</tr>
</tbody>
@endforeach
</table>
{{-- Pagination --}}
<div class="d-flex justify-content-center">
{!! $proposals->links() !!}
</div>
</div>
</div>
</div>
</div>

Controller

public function PageCustomer(Request $request)
{
$data = $request->all();
$customer = customer::where('id_customer', $data['id_customer'])->first();
$proposals = proposal::where('id_customer', $customer['id_customer'])->paginate(5);

return view('admin.customer.page_customer', compact('customer', 'proposals'));
}

没有传到第二页的变量是$customer我尝试传递一个数组,其中包含 name 和 email 的值,但没有成功。我该如何解决这种情况?

最佳答案

在分页器上使用appends:

{!! $proposals->appends(['customer' => $customer])->links() !!}

Laravel 7 开始,您可以在 Paginator 实例上调用 withQueryString() 方法:

{!! $proposals->withQueryString()->links() !!}

withQueryString() method appends all current query string values to the pagination links.

关于php - 通过 Blade 分页传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65021623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com