Orvyl
Orvyl

Reputation: 2775

Laravel 4 eloquent Mass assignment error in fillable

I'm currently studying eloquent of L4 and I encountered this mass assignment. I'd follow the instructions and I know you need to setup your $fillable to use the create method but I am still receiving a blank row in the database. here's my code:

MODEL:

class User extends Eloquent  
{
    protected $fillable = array('email','pwd','active','name');
}

CONTROLLER:

$user = new User;
$add = array(
    'name'=>Input::get('custname'),
    'active'=>1,
    'pwd'=>Hash::make(Input::get('pwd')),
    'email'=>Input::get('email')
);

return var_dump($user->create($add));

I also did: CONTROLLER

$add = array(
'name'=>Input::get('custname'),
'active'=>1,
'pwd'=>Hash::make(Input::get('pwd')),
'email'=>Input::get('email')
);

return var_dump(User::create($add));

But still the same result.

Upvotes: 1

Views: 3640

Answers (2)

Mandeep Gill
Mandeep Gill

Reputation: 4885

Yes with new version you can use public or protected keywords.

Simple use this :

protected $fillable = [‘email’, ‘pwd’,’active’,’name’];

You can also specify table name if you are working with other Model like this :

public $table = ‘users’

This is working fine after run composer update on the root of project directory.

Upvotes: 0

Felix
Felix

Reputation: 812

There was a bug causing this, see https://github.com/laravel/framework/issues/1548 Should be fixed now, run composer update to get the newest version of laravel/framework

Upvotes: 1

Related Questions