我尝试使用 laravel 中的表单外观更新用户对象,提交后出现错误:
ErrorException in Grammar.php line 102:
Argument 1 passed to Illuminate\Database\Grammar::columnize() must be of the type array,
string given, called in
C:\Laravel Projects\ExpenseTool\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 105 and defined
我的请求:
<?php namespace App\Http\Requests;
use App\Http\Requests\Request;
class UserRequest extends Request {
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|min:3',
'email'
];
}
}
我的 HomeController 索引:
public function index()
{
$user = Auth::user();
return view('Expenses.home', compact( 'user'));
}
我在Expenses.home中的表格:
{!! Form::model($user, ['method' => 'PUT', 'action' => ['HomeController@update', $user->id]]) !!}
<div class="form-group">
{!! Form::label('Name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('Email', 'Email:') !!}
{!! Form::text('email', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit('Update', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
我的路线:
Route::resource('home', 'HomeController', ['only' => ['update']]);
我的家庭控制器@更新:
public function update($id, UserRequest $request)
{
$loggedUser = Auth::user();
$userDB = User::get($id);
$username = $request->input('name');
$userDB->name = $username;
$userDB->update();
return redirect('home');
}
我究竟做错了什么?