我正在使用表格中的序列号进行过滤,但是当我单击按钮错误时,像这样
“方法链接不存在”
这是我的控制器
public function show(Request $request)
{
$instrument = Instrument::when($request->serial_number, function ($query) use ($request) {
$query->where('serial_number', 'like', "%{$request->serial_number}%");
})->paginate(5);
$instrument->appends($request->only('serial_number'));
return view('settinginstrument.index', compact('settinginstrument'));
}
这是我的刀刃:
<table class="table">
@foreach ($instruments as $instrument)
<tr>
<td>
Serial Number : {{ $instrument->serial_number }}
@if($instrument->customer !== NULL)
<div class="text-muted"><i class="fa fa-hospital-o" aria-hidden="true"></i> {{ $instrument->customer->name }}</div>
@endif
@if($instrument->contractType !== NULL)
<div class="text-muted"><i class="fa fa-compress" aria-hidden="true"></i> {{ $instrument->contractType->name }}</div>
@endif
</td>
<td>
<div class="pull-right">
<a type="button" href="{{ route('instrument.edit', ['instrumentType' => $instrumentType->id, 'instrument' => $instrument->id]) }}"
class="btn btn-success ">
<i class="fa fa-pencil"></i> Edit
</a>
@if($instrument->customer == NULL || $instrument->contractType == NULL)
<a href="{{ route('instrument.destroy', ['instrumentType' => $instrumentType->id, 'instrument' => $instrument->id]) }}"
data-method="delete" data-confirm="" class="btn btn-danger">
<i class="fa fa-trash"></i> <span class="hidden-xs">Delete</span>
</a>
@endif
</div>
</td>
</tr>
@endforeach
</table>
<div class="paginator text-center">{{ $instruments->links() }}</div>
@else
....................................
我的代码哪里出错?
答案 0 :(得分:0)
当记录计数为零并且尝试访问links()时,会发生此问题 添加条件以检查记录是否存在。
@if($instruments)
<div class="paginator text-center">{{ $instruments->links() }}</div>
@endif
在控制器中,您还遇到一个错字错误$instruments
和$instrument
我建议在foreach
上方添加条件
并在空白结果上显示一些未找到记录的消息。
更新
同时将$instruments
传递到光头
$instruments = Instrument::when($request->serial_number, function ($query) use ($request) {
$query->where('serial_number', 'like', "%{$request->serial_number}%");
})->paginate(5);
$instruments->appends($request->only('serial_number'));
return view('settinginstrument.index', compact('instruments'));
答案 1 :(得分:0)
您没有将参数传递给视图:
public function show(Request $request)
{
$instruments = Instrument::when($request->serial_number, function ($query) use ($request) {
$query->where('serial_number', 'like', "%{$request->serial_number}%");
})->paginate(5);
$instrument->appends($request->only('serial_number'));
return view('settinginstrument.index',['instruments' => $instruments);
}
然后在刀片服务器上:
{{$instruments->links()}}