我是laravel的新手,我希望通过用户ID 获取用户的单个记录并显示在输入值中。请指导我
public function profile(){
$userdata = User::all();
return view('pages/edit-profile')->with('userdata',$userdata);
}
Route::get('profile', 'PageController@profile_c');
<form class="form-horizontal" role="form" action="/edit_profile" method="post">
{{ csrf_field() }}
<div class="form-group">
<label class="col-lg-3 control-label">First name:</label>
<div class="col-lg-8">
<input class="form-control" name="firstName" id="firstName" type="text" value="Jane">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Last name:</label>
<div class="col-lg-8">
<input class="form-control" name="lastName" id="lastName" type="text" value="Bishop">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Display name:</label>
<div class="col-lg-8">
<input class="form-control" name="displayName" id="displayName" type="text" value="Jane Bishop">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Email:</label>
<div class="col-lg-8">
<input class="form-control" name="email" id="email" disabled type="email" value="janesemail@gmail.com">
</div>
</div>
</form>
答案 0 :(得分:6)
以用户身份获取用户
$user = User::find(id);
return view('pages/edit-profile', compact('user));
如果您了解用户的其他信息,例如用户电子邮件
$user = User::where('email', $email)->first();
return view('pages/edit-profile', compact('user));
在表单中,如果您使用的是刀片
<input name="email" value={{ $user->email }} />
更重要的是,如何使用ELoquent:https://laravel.com/docs/5.4/eloquent