这是我的提交表格:
` @csrf
<div class="form-group">
<label>{{__('psm::general.passport')}}</label>
<input class="form-control" name ="passport" value="{{$profiles->passport ?? null}}">
</div>
<div class="form-group">
<label>{{__('psm::general.nric')}}</label>
<input class="form-control" name="mykad" value="{{$profiles->mykad ?? null}}">
</div>
<div class="form-group">
<label>{{__('psm::general.fullName')}}</label>
<input type="text" class="form-control" name="name" value="{{$profiles->name ?? null}}">
</div>
`
这是我的控制器:
` 公共函数 show($id) {
$profiles = profiles::where('user_id', $id)->first();
return view('psm::pengurusan-staf.show');
}`
这是我的路线:
Route::get('psm/pengurusan-staf/show/{id}', 'PengurusanStafController@show')->name('psm.pengurusan-staf.show');
我使用 laragon 作为数据库。
这就是我想要显示的数据。 这是我的 show.blade.php:
` <div class="form-group">
<label>{{__('psm::general.passport')}}</label>
<li>{{$profiles->passport ?? null}}</li>
</div>
<div class="form-group">
<label>{{__('psm::general.nric')}}</label>
<li>{{$profiles->mykad ?? null}}</li>
</div>
<div class="form-group">
<label>{{__('psm::general.fullName')}}</label>
<li>{{$profiles->name ?? null}}</li>
</div>`
我应该写路线表格吗?例如在此 show.blade.php 中,我需要制作
<form action="{{route('psm.pengurusan-staf.show')}}" method="POST"> @csrf @method('get') //my show.blade.php </form?
在
show
中的 PengurusanStafController
方法中,您正在获取配置文件数据,但没有将其传递到视图。您需要将 $profiles
变量传递给视图,以便您可以在 show.blade.php
文件中访问它。
public function show($id)
{
$profiles = profiles::where('user_id', $id)->first();
return view('psm::pengurusan-staf.show', ['profiles' => $profiles]);
}