LARAVEL:当我想更新数据库时,参数太少了
我必须为酒店开发预订系统。 您首先必须创建用户,而不是预订。 可以选择编辑注册用户,但这是我卡住的部分。 我遵循一个非常好的教程,但是目前我无法从他的视频,互联网或文档中弄清楚我的错误。.
我已经使用了帖子方法将新数据插入数据库中,但是要编辑数据并进行更新,我必须使用PUT方法。但这给出了一个错误:“我的函数中的参数太少了。1通过,2个预期”。
我知道我必须在每次更改时都会
!
public function store(Request $request)
{
$guest = Guest::create
([
'titel' => $request->input('title'),
'voornaam' => $request->input('fname'),
'achternaam' => $request->input('sname'),
'adres' => $request->input('address'),
'postcode' => $request->input('zipcode'),
'stad' => $request->input('city'),
'provincie' => $request->input('provincie'),
'email' => $request->input('email')
]);
return redirect('./clients.html');
}
public function edit($id)
{
$guest = Guest::find($id);
return view('edit')->with('guest', $guest);
}
public function update(Request $request, $id)
{
$guest = Guest::where('id', $id)
->update([
'titel' => $request->input('title'),
'voornaam' => $request->input('fname'),
'achternaam' => $request->input('sname'),
'adres' => $request->input('address'),
'postcode' => $request->input('zipcode'),
'stad' => $request->input('city'),
'provincie' => $request->input('provincie'),
'email' => $request->input('email')
]);
}
路线
Route::get('/', [PagesController::class, 'home']);
Route::get('/home.html', [PagesController::class, 'home']);
Route::get('/clients.html', [GuestsController::class, 'saveGuests']);
Route::post('/clients.html', [GuestsController::class, 'store']);
Route::put('/clients.html', [GuestsController::class, 'update']);
Route::get('/reservations.html', [PagesController::class, 'reservations']);
Route::get('/clients_new.html', [GuestsController::class, 'newclients']);
Route::get('/clients/{id}/edit.html', [GuestsController::class, 'edit']);
Route::get('/reservations_new.html', [PagesController::class, 'newReservations']);
缓存 put方法):
<form action="/clients.html" method="POST" class="w-3/12 m-auto flex flex-col justify-evenly items-center text-xl">
@csrf
@method('PUT')
<div class="medium-6 columns py-4 text-3xl w-full flex flex-row items-center justify-between">
<label class="font-semibold">Titel</label>
<select name="title" class="w-22 border-solid border-2 border-grey-200 rounded-lg bg-gray-100 p-2" value="{{ $guest->titel }}">
<option value="Mr." selected="selected">Mr.</option>
<option value="Ms.">Mw.</option>
<option value="Mrs.">Juf.</option>
<option value="Dr.">Dr.</option>
</select>
</div>
<div class="medium-6 columns m-auto py-4 text-3xl w-full flex flex-row items-center justify-between">
<label class="font-semibold">Voornaam</label>
<input name="fname" type="text" class="border-solid border-2 border-grey-200 rounded-lg bg-gray-100 p-2 " value="{{ $guest->voornaam }}">
</div>
<div class="medium-6 columns m-auto py-4 text-3xl w-full flex flex-row items-center justify-between">
<label class="font-semibold">Achternaam</label>
<input name="sname" type="text" class="border-solid border-2 border-grey-200 rounded-lg bg-gray-100 p-2" value="{{ $guest->achternaam }}">
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
控制器功能:
以表格:
我也鼓励您检查和路由
Controller functions:
in the form:
also i would encourage you to check the documentation for Laravel Validation and Routing
将此代码用于路由:
将此代码用于控制器:
在形式中:
使用此代码在更新时显示错误:
我希望它将有用
Use this code for routes :
Use this code for Controller:
in form :
Use this code to display errors when updating:
I hope it will be useful