在 Laravel 中分页时的非法运算符和值组合
Illegal operator and value combination when paginating in Laravel
我是 Laravel 6 的新手。在视图中,我创建了一个表单,当它被提交时,它应该 return 一个 table 过滤在底部的 links 分页。一切正常,但是当我点击分页的link时出现以下错误:"Illegal operator and value combination."
我什至尝试在视图中使用 "render" 方法,但没有任何改变。我看到了 link,但是当我点击其中之一时,错误出现了。
查看
@if (isset($meetings))
<div class="container">
<table class="table table-condensed table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>Participants</th>
<th>Description</th>
<th>Room</th>
<th>Date</th>
<th>Start Hour</th>
<th>End Hour</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
@foreach($meetings as $meeting)
<tr>
<td>{{ $meeting->id }}</td>
<td>{{ $meeting->id_participants }}</td>
<td>{{ $meeting->description }}</td>
<td>{{ $meeting->id_room }}</td>
<td>{{ $meeting->date }}</td>
<td>{{ $meeting->start_hour }}</td>
<td>{{ $meeting->end_hour }}</td>
<td><a href="{{ route('updateMeeting', ['id' => $meeting->id]) }}" class= "text-center"><button type="button" class="btn btn-primary">Edit</button></a></td>
<td>
<form action="{{ route('nextMeetingsDeleteMeeting', ['id' => $meeting->id]) }}" method="POST">
@csrf
{{ method_field('PUT') }}
<button type="submit" class="btn btn-danger" id={{ $meeting->id }}>Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
<div>
{{ $meetings->links() }}
</div>
</div>
@endif
控制器
public function fetch_table(Request $request)
{
$this->validate($request, [
'start_date' => 'date',
'end_date' => 'date',
]);
$start_date = $request['start_date'];
$end_date = $request['end_date'];
$participants = $request['participants'];
$room_input = $request['rooms'];
$rooms = Room::all();
$users = User::all()->where('is_active', '1')->sortBy('surname');
$meetings = $this->build_table($room_input, $start_date, $end_date, $participants);
return view('reportArea', compact('users', 'rooms', 'meetings', 'start_date', 'end_date', 'participants',
'room_input'))->withInput($request->all());
}
public function build_table($room, $start_date, $end_date, $participants)
{
if (!empty($room) && !empty($participants)) {
$meetings = DB::table('meetings')
->where('is_active', '1')
->where('id_room', $room)
->where('date', '>', $start_date)
->where('date', '<', $end_date)
->where(function ($query) use ($participants) {
$query->where('id_participants', $participants)
->orWhere('id_participants', 'like', '%;'.$participants)
->orWhere('id_participants', 'like', $participants.';%')
->orWhere('id_participants', 'like', '%;'.$participants.';%');
})
->paginate(2);
} elseif (!empty($participants)) {
$meetings = DB::table('meetings')
->where('is_active', '1')
->where('date', '>', $start_date)
->where('date', '<', $end_date)
->where(function ($query) use ($participants) {
$query->where('id_participants', $participants)
->orWhere('id_participants', 'like', '%;'.$participants)
->orWhere('id_participants', 'like', $participants.';%')
->orWhere('id_participants', 'like', '%;'.$participants.';%');
})
->paginate(2);
} elseif (!empty($rooms)) {
$meetings = DB::table('meetings')
->where('is_active', '1')
->where('date', '>', $start_date)
->where('date', '<', $end_date)
->where('id_room', $room)
->paginate(2);
} else {
$meetings = DB::table('meetings')
->where('is_active', '1')
->where('date', '>', $start_date)
->where('date', '<', $end_date)
->paginate(2);
}
return $meetings;
}
路线
Route::get('/reportarea/fetchtable', 'ReportAreaController@fetch_table')->name('reportAreaFetchTable');
目前,一切正常,但当我点击link时,出现上述错误。换句话说,如果我添加方法 paginate(2)
,我只能正确地看到 table 上的两行,但是当我单击 link 以查看其他行时,它无法正常工作.有人能帮我解决这个问题吗?
您可能需要 附加 到寻呼机链接的查询字符串,以传递您需要的其他参数。您将 null
作为这些查询参数的值传递并收到错误。
举个例子:
{{ $meetings->appends(['start_date' => ..., 'end_date' => ..., ...])->links() }}
或者只传递所有当前查询参数(分页器将忽略当前页面使用的任何键):
{{ $meetings->appends(request()->query())->links() }}
Laravel 6.x Docs - Pagination - Displaying Results - Appending To Pagination Links
Laravel 6.x Docs - Requests - Retrieving Input - Retrieving Input From The Query String
我是 Laravel 6 的新手。在视图中,我创建了一个表单,当它被提交时,它应该 return 一个 table 过滤在底部的 links 分页。一切正常,但是当我点击分页的link时出现以下错误:"Illegal operator and value combination."
我什至尝试在视图中使用 "render" 方法,但没有任何改变。我看到了 link,但是当我点击其中之一时,错误出现了。
查看
@if (isset($meetings))
<div class="container">
<table class="table table-condensed table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>Participants</th>
<th>Description</th>
<th>Room</th>
<th>Date</th>
<th>Start Hour</th>
<th>End Hour</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
@foreach($meetings as $meeting)
<tr>
<td>{{ $meeting->id }}</td>
<td>{{ $meeting->id_participants }}</td>
<td>{{ $meeting->description }}</td>
<td>{{ $meeting->id_room }}</td>
<td>{{ $meeting->date }}</td>
<td>{{ $meeting->start_hour }}</td>
<td>{{ $meeting->end_hour }}</td>
<td><a href="{{ route('updateMeeting', ['id' => $meeting->id]) }}" class= "text-center"><button type="button" class="btn btn-primary">Edit</button></a></td>
<td>
<form action="{{ route('nextMeetingsDeleteMeeting', ['id' => $meeting->id]) }}" method="POST">
@csrf
{{ method_field('PUT') }}
<button type="submit" class="btn btn-danger" id={{ $meeting->id }}>Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
<div>
{{ $meetings->links() }}
</div>
</div>
@endif
控制器
public function fetch_table(Request $request)
{
$this->validate($request, [
'start_date' => 'date',
'end_date' => 'date',
]);
$start_date = $request['start_date'];
$end_date = $request['end_date'];
$participants = $request['participants'];
$room_input = $request['rooms'];
$rooms = Room::all();
$users = User::all()->where('is_active', '1')->sortBy('surname');
$meetings = $this->build_table($room_input, $start_date, $end_date, $participants);
return view('reportArea', compact('users', 'rooms', 'meetings', 'start_date', 'end_date', 'participants',
'room_input'))->withInput($request->all());
}
public function build_table($room, $start_date, $end_date, $participants)
{
if (!empty($room) && !empty($participants)) {
$meetings = DB::table('meetings')
->where('is_active', '1')
->where('id_room', $room)
->where('date', '>', $start_date)
->where('date', '<', $end_date)
->where(function ($query) use ($participants) {
$query->where('id_participants', $participants)
->orWhere('id_participants', 'like', '%;'.$participants)
->orWhere('id_participants', 'like', $participants.';%')
->orWhere('id_participants', 'like', '%;'.$participants.';%');
})
->paginate(2);
} elseif (!empty($participants)) {
$meetings = DB::table('meetings')
->where('is_active', '1')
->where('date', '>', $start_date)
->where('date', '<', $end_date)
->where(function ($query) use ($participants) {
$query->where('id_participants', $participants)
->orWhere('id_participants', 'like', '%;'.$participants)
->orWhere('id_participants', 'like', $participants.';%')
->orWhere('id_participants', 'like', '%;'.$participants.';%');
})
->paginate(2);
} elseif (!empty($rooms)) {
$meetings = DB::table('meetings')
->where('is_active', '1')
->where('date', '>', $start_date)
->where('date', '<', $end_date)
->where('id_room', $room)
->paginate(2);
} else {
$meetings = DB::table('meetings')
->where('is_active', '1')
->where('date', '>', $start_date)
->where('date', '<', $end_date)
->paginate(2);
}
return $meetings;
}
路线
Route::get('/reportarea/fetchtable', 'ReportAreaController@fetch_table')->name('reportAreaFetchTable');
目前,一切正常,但当我点击link时,出现上述错误。换句话说,如果我添加方法 paginate(2)
,我只能正确地看到 table 上的两行,但是当我单击 link 以查看其他行时,它无法正常工作.有人能帮我解决这个问题吗?
您可能需要 附加 到寻呼机链接的查询字符串,以传递您需要的其他参数。您将 null
作为这些查询参数的值传递并收到错误。
举个例子:
{{ $meetings->appends(['start_date' => ..., 'end_date' => ..., ...])->links() }}
或者只传递所有当前查询参数(分页器将忽略当前页面使用的任何键):
{{ $meetings->appends(request()->query())->links() }}
Laravel 6.x Docs - Pagination - Displaying Results - Appending To Pagination Links
Laravel 6.x Docs - Requests - Retrieving Input - Retrieving Input From The Query String