【发布时间】:2021-04-04 22:52:24
【问题描述】:
提交注册表后,我想将其重定向到编辑/更新表单,但出现错误。编辑/更新表单是根据用户插入的注册表单从数据库中获取值。因此,每个用户都可以查看他们输入的表单并进行更新。
404 |未找到
编辑表单是homedit.blade.php。这是代码。
<form method="post" action="{{route(homedit,$hm->id)}}" enctype="multipart/form-data">
@csrf
<label for="fullName"><b>Full Name as per NRIC :</b></label>
<input type="text" class="form-control" name="fullName" value="{{$hm['fullName']}}"/>
<label for="icno"><b>I/C No :</b></label>
<input type="tel" class="form-control" name="icno" pattern="[0-9]{12}" value="{{$hm['icno']}}"/>
<label for="email"><b>Email :</b></label>
<input type="text" class="form-control" name="email" value="{{Auth::user()->email}}"/>
<label for="gender"><b>Gender :</b></label>
<select name="gender" id="gender" class="form-control" >
@foreach ($hm as $home)
<option value="{{$hm['id']}}"> {{$hm['gender']}}</option>
@endforeach
<option value="female"> female</option>
</select>
</form>
这是控制器的代码
public function createhome(Request $request)
{
return view('home');
}
public function home(Request $request)
{
$hm = new Register();
$hm->fullName = $request->input('fullName');
$hm->icno = $request->input('icno');
$hm->email = $request->input('email');
$hm->gender = $request->input('gender');
$hm->record_id = Auth::user()->id;
$hm->save();
return redirect('/homedit')->with('success', 'Your personal details have been saved!');
}
public function updatehome(Request $request, $id)
{
$hm = Register::find($id);
$hm->fullName = $request->fullName;
$hm->icno = $request->icno;
$hm->email = $request->email;
$hm->gender = $request->gender;
$hm->save();
return redirect('/homedit')->with('success', 'Your personal details have been updated!');
}
public function edithome($id){
$hm = Register::find($id);
return view('homedit', compact ('hm'));
}
这是 web.php 的代码
Route::get('/home', 'App\Http\Controllers\ApplicantController@createhome');
Route::post('/home', 'App\Http\Controllers\ApplicantController@home');
Route::get('/homedit/{id}', 'App\Http\Controllers\ApplicantController@edithome');
Route::post('/homedit/{id}', 'App\Http\Controllers\ApplicantController@updatehome');
【问题讨论】:
-
欢迎来到 SO ... 在重定向到该 URI 时,您需要为该路由
/homedit/{id}的{id}段传递一些东西
标签: php html laravel routes controller