Laravel Eloquent - $fillable is not working?

eloquent, laravel

Solution

Change following:

->update(Input::all());

to this (exclude the `_method` from the array)

->update(Input::except('_method'));

Update:

Actually following `update` method is being called from `Illuminate\Database\Eloquent\Builder` class which is being triggered by `_call` method of `Illuminate\Database\Eloquent\Relations` class (because you are calling the `update` on a relation) and hence the `$fillable` check is not getting performed and you may use `Input::except('_method')` as I answered:

public function update(array $values)
{
    return $this->query->update($this->addUpdatedAtColumn($values));
}

If you directly call this on a Model (Not on a relation):

Positions::find($id)->update(Input::all());

Then this will not happen because `fillable` check will be performed within `Model.php` because following `update` method will be called from `Illuminate\Database\Eloquent\Model` class:

public function update(array $attributes = array())
{
    if ( ! $this->exists)
    {
        return $this->newQuery()->update($attributes);
    }

    return $this->fill($attributes)->save();
}

Problem

I have set the variable `$fillable` in my model. I wanted to test the `update` functionality, and I get this error: SQLSTATE[42S22]: Column not found: 1054 Unknown column '_method' in 'field list' (SQL: update `positions` set `name` = Casual Aquatic Leader, `_method` = PUT, `id` = 2, `description` = Here is my description, `updated_at` = 2014-05-29 17:05:11 where `positions`.`client_id` = 1 and `id` = 2)" Why is this yelling at `_method` when my fillable doesn't have that as a parameter? My update function is: ``` Client::find($client_id) ->positions() ->whereId($id) ->update(Input::all()); ```

Original source