Я пытаюсь показать, обновить и удалить запись из двух разных таблиц.
Вот функция показа контроллера:
public function show($user_id)
{
//
$staffinfo = Staff::find($user_id); // Loading all data from
$userinfo = User::find($user_id);
return view('staff.view')
->with('staffinfo', $staffinfo)
->with('userinfo', $userinfo);
}
Вот код view.blade.php:
<table class="table table-hover table-dark">
<tbody>
<tr>
<th scope="row">Name</th>
<td>{{ $staffinfo->name }}</td>
</tr>
<tr>
<th scope="row">Mobile</th>
<td>{{ $userinfo->mobile }}</td>
</tr>
<tr>
<th scope="row">Designation</th>
<td>{{ $staffinfo->designatin }}</td>
</tr>
</tbody>
</table>
Редактирование и обновление функции в контроллере:
public function edit($user_id)
{
//
$staffinfo = Staff::find($user_id); // Loading all data from
$userinfo = User::find($user_id);
return view('staff.edit')
->with('staffinfo', $staffinfo)
->with('userinfo', $userinfo);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $user_id)
{
//
$staffinfo = Staff::find($user_id);
$staffinfo->name = $request->input('stfname');
$staffinfo->user_id = $request->input('stfid');
$staffinfo->designaton = $request->input('stfdesig');
$staffinfo->dob = $request->input('staffdob');
$staffinfo->save();
$userinfo = User::find($user_id);
$userinfo->user_id = $request->input('stfid');
$userinfo->user_type = $request->input('stfdesig');
$userinfo->mobile = $request->input('staffmobile');
$userinfo->email = $request->input('staffmail');
$userinfo->password = $request->input('staffpw');
$userinfo->save();
}
edit.blade.php код некоторой части:
<h2>Update Staff</h2>
<form method="post" action="{{ route('staff.update', $staffinfo->user_id) }}" enctype="multipart/form-data">
@method('PATCH')
@csrf
<div class="form-row">
<div class="form-group col-md-3">
<label for="stfdesig">Designation</label>
<input type="text" name="stfdesig" value="{{ $staffinfo->designation }}" class="form-control" id="stfid"
</div>
<div class="form-group col-md-3">
<label for="stfid">ID</label>
<input type="text" name="stfid" value="{{ $staffinfo->user_id }}" class="form-control" id="stfid">
</div>
<div class="form-group col-md-6">
<label for="stfname">Name</label>
<input type="text" name="stfname" value="{{ $staffinfo->name }}" class="form-control" id="stfname">
</div>
<div class="form-group col-md-6">
<label for="stfmobile">Mobile</label>
<input type="text" name="stfmobile" value="{{ $userinfo->mobile }}" class="form-control" id="stfmobile">
</div>
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
Ошибка просмотра страницы:
Попытка получить свойство 'name' необъекта (Просмотр:
F: \ XAMPP \ HTDOCS \ gchsc \ ресурсы \ вид \ Персонал \ view.blade.php)
Ошибка редактирования страницы:
Попытка получить свойство 'user_id' необъекта (Просмотр:
F: \ XAMPP \ HTDOCS \ gchsc \ ресурсы \ вид \ Персонал \ edit.blade.php)