您可以尝试 Laravel 表单模型绑定。参考链接
路线:
Route::get('/user/edit/{id}', [
'as' => 'updateUser',
'uses' => 'UserController@getUserEditFrom'
]);
控制器:
public function getUserEditFrom($id, UserRepository $userRepository)
{
return view('users.edit', [
'user' => $userRepository->find($id)
]);
}
看法
{!! Form::model($user, ['url' => route('updateUser', ['id' => $user->id])]) !!}
<div class="form-group {{ $errors->first('name', 'has-error') }}">
{!! Form::label('name', 'Name *') !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
{!! $errors->first('name', '<span class="help-block">:message</span>') !!}
</div>
<div class="form-group {{ $errors->first('username', 'has-error') }}">
{!! Form::label('username', 'Username *') !!}
{!! Form::text('username', null, ['class' => 'form-control']) !!}
{!! $errors->first('username', '<span class="help-block">:message</span>') !!}
</div>
<div class="form-group {{ $errors->first('email', 'has-error') }}">
{!! Form::label('email', 'Email *') !!}
{!! Form::text('email', null, ['class' => 'form-control']) !!}
{!! $errors->first('email', '<span class="help-block">:message</span>') !!}
</div>
{!! Form::close() !!}