Do you get the error when you SHOW the form or when you POST the form ?
Jun 11, 2018
34
Level 1
On checkbox update this error: Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id
I have a table with checkbox where I only need to update just that checkbox, where default value is 0 and boolean in migration. CallCenterController look like this:
public function edit($id)
{
$callCenter = AddMember::findOrFail($id);
return view('callcenter.index', compact('callCenter'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$callCenter = AddMember::findOrFail($id);
$callCenter->update($request->all());
return redirect()->back();
}
and view like this:
{!! Form::model($callCenter, ['method'=>'PATCH', 'action'=>['CallCenterController@update', $callCenter->id]]) !!}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Last Name</th>
<th>Confirmed</th>
</tr>
</thead>
<tbody>
@if ($callCenter)
@foreach ($callCenter as $call)
<tr @if ($call->confirmed) class="success" @endif>
<td>{{$call->name}}</td>
<td>{{$call->last_name}}</td>
<td><input type="checkbox" name="confirmed" @if ($call->confirmed) checked=checked @endif></td>
</tr>
@endforeach
@endif
</tbody>
</table>
</div>
<div class="form-group">
{!! Form::submit('Confirm', ['class'=>'btn btn-primary pull-right']) !!}
</div>
{!! Form::close() !!}
but I have this error:
(2/2) ErrorException Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id
when I try to enter that page... I already try without pagination and same error appear so it's not that. Any idea?
Level 122
Switch the form for this;
<form action="{{ url('CallCenterController@confirm') }}" method="post">
{{ csrf_field() }}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Last Name</th>
<th>Confirmed</th>
</tr>
</thead>
<tbody>
@if ($callCenter)
@foreach ($callCenter as $call)
<tr @if ($call->confirmed) class="success" @endif>
<td>{{$call->name}}</td>
<td>{{$call->last_name}}</td>
<td>
<input type="hidden" value="0" name="confirmed[{{ $call->id }}]" />
<input type="checkbox" name="confirmed[{{ $call->id }}]" @if ($call->confirmed) checked=checked @endif />
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
</div>
<div class="form-group">
{!! Form::submit('Confirm', ['class'=>'btn btn-primary pull-right']) !!}
</div>
</form>
Then you have a form which contains a confirmed field for each $call
create a new route to a new method in the controller
Route::post('name your route here', 'CallCentreController@confirm');
/**
* Update the confirmed
*/
public function confirm(Request $request)
{
foreach($request->confirmed as $key => $value) {
AddMember::update($key, $value);
}
return redirect(route('callcenter.index'));
}
1 like
Please or to participate in this conversation.