下面的代码包括roop语句和分页。 我也希望遵循MVC样式编码,但在这种情况下,我必须在下面的视图中使用@if语句。
当我尝试按@if(!deleted_at == null)过滤时出错,但我无法显示正确的分页,因为此代码也用“(deleted_at == null)”计数,所以结果是显示的分页编号不正确。
如何在传递此控制器后修改此代码以获得正确的分页结果?
我认为错误来自使用Where()和Orwhere() 感谢:)
按user_name和customer_name搜索框
的index.php
<div style="overflow-x: auto; display: inline-flex;">
{!! Form::open(array('class' => 'form', 'method' => 'get', 'url' => url('/stopjobs/job_finished_search_date'))) !!}
{{ Form::input('text', 'datepicker_from', null, ['placeholder' => 'Fra', 'id' => 'datepicker_from']) }}
{{ Form::input('text', 'datepicker_to', null, ['placeholder' => 'Til', 'id' => 'datepicker_to']) }}
{!! Form::submit('Søke', ['class' => 'btn btn-success btn-sm']) !!}
{!! Form::close() !!}
{!! Form::open(array('class' => 'form', 'method' => 'get', 'url' => url('/stopjobs/job_finished_search_name'))) !!}
{!! Form::text('name', null, ['placeholder' => 'Bruker eller Kunde']) !!}
{!! Form::submit('Søke', ['class' => 'btn btn-success btn-sm']) !!}
{!! Form::close() !!}
</div>
控制器
public function job_finished_search_name(Request $request)
{
$jobs = Job::onlyTrashed()
->where('user_name', 'like', '%'.$request->name.'%')
->orwhere('customer_name', 'like', '%'.$request->name.'%')
->orderBy('deleted_at', 'desc')
->paginate(15);
return view('stopjobs.index', ['jobs' => $jobs]);
}
查看
<tbody>
@foreach($jobs as $job)
@if(!$job->deleted_at == null)
<tr>
<td>{!! $job->id !!}</td>
<td>{!! $job->user_name !!}</td>
<td>{!! $job->created_at !!}</td>
<td>{!! $job->deleted_at !!}</td>
<td>{!! $job->usedTime() !!}</td>
</tr>
@endif
@endforeach
</tbody>
</table>
</div>
{{ $jobs->links()}}
答案 0 :(得分:0)
查询作业时,请使用 var car = "M17.402,0H5.643C2.526,0,0,3.467,0,6.584v34.804c0,3.116,2.526,5.644,5.643,5.644h11.759c3.116,0,5.644-2.527,5.644-5.644 V6.584C23.044,3.467,20.518,0,17.402,0z M22.057,14.188v11.665l-2.729,0.351v-4.806L22.057,14.188z M20.625,10.773 c-1.016,3.9-2.219,8.51-2.219,8.51H4.638l-2.222-8.51C2.417,10.773,11.3,7.755,20.625,10.773z M3.748,21.713v4.492l-2.73-0.349 V14.502L3.748,21.713z M1.018,37.938V27.579l2.73,0.343v8.196L1.018,37.938z M2.575,40.882l2.218-3.336h13.771l2.219,3.336H2.575z M19.328,35.805v-7.872l2.729-0.355v10.048L19.328,35.805z";
var icon = {
path: car,
scale: .7,
strokeColor: 'white',
strokeWeight: .10,
fillOpacity: 1,
fillColor: '#404040',
offset: '5%',
anchor: new google.maps.Point(10, 25)
};
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i]['LAT'], locations[i]['LON']),
map: map,
icon: icon,
});
语句执行此操作。没有其他办法
where
答案 1 :(得分:0)
如果您只想显示带有分页的软删除数据,请尝试使用
$jobs = Job::onlyTrashed()
->where('key', 'value')
->paginate();