控制器:
public function updateTeachers(Request $request, User $teachers){
$validated = $request->validate([
"name" => ['required'],
"email" => ['required'],
]);
$teachers->update($validated);
return back()->with('information-message', 'Data was successfully updated');
字符串
}
查看:
<form action="/teacher/{{ $dataTeacher->id }}" method="POST" class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-80 px-4 py-3">
@method('PUT')
@csrf
<div class="flex flex-wrap -mx-3 mb-6">
<div class="w-full px-3">
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-first-name">
Name
</label>
<input type="text" name="name" value="{{ $dataTeacher->name }}" class="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white focus:border-gray-500" required>
</div>
</div>
<div class="flex flex-wrap -mx-3 mb-6">
<div class="w-full px-3">
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-password">
Email
</label>
<input type="email" name="email" value="{{ $dataTeacher->email}}" class="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white focus:border-gray-500" required>
</div>
</div>
<button type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Push</button>
型
路线:
Route::put('/teacher/{teacher}', [UserController::class, 'updateTeachers']);
型
我的更新代码是否有误?它不工作,它只显示信息-消息。
如何在laravel中使用更新?
2条答案
按热度按时间vwkv1x7d1#
其实有很多方法可以更新它。
首先,确保您的模型已将“
name
”和“email
”添加到fillable属性。第二步:
字符串
第三步:
型
第四步:
型
其中一个可能对你有帮助。试试这些方法。
快乐编程
flseospp2#
字符串
的数据