Laravel 5 - 使用 Form Facade 更新时出错

Laravel 5 - Error updating with Form Facade

我尝试使用 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']]);

我的 HomeController@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');
}

我做错了什么?

你必须改变

`public 函数更新($id, UserRequest $request) { $loggedUser = Auth::user();

// you are cool to use findOrFail
$userDB = User::find($id);

$username = $request->input('name');

$userDB->name = $username;

$userDB->update();

return redirect('home');

}`

您的错误是由于 get() 方法要求您传递要从数据库中检索的列的数组