dimanche 27 mars 2016

Laravel 5 - Error updating with Form Facade

Im trying to update the user object using a form facade in laravel, after submiting i get the error:

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

My request:

<?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'
    ];
}

}

My HomeController index:

public function index()
{
    $user = Auth::user();
    return view('Expenses.home', compact( 'user'));
}

My form in view 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() !!}

my route:

Route::resource('home', 'HomeController',  ['only' => ['update']]);

my 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');
}

What am i doing wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire