0

In my Unit Test in Laravel I am setting the currently authenticated user with the code below. This is exactly how Laravel documented it on their website. I use the default User model which Laravel provide.

public function testLoggedInUserCanCreateCat() {
        Route::enableFilters();
        $user = new User(array(
            'name' => 'john'
        ));
        $this->be($user);
        $this->call('GET', '/cats/create');
        $this->assertResponseOk();
    }

For some reason, when I run phpunit in SSH, I get the following error:

1) GlobalTest::testLoggedInUserCanCreateCat
Illuminate\Database\Eloquent\MassAssignmentException: name

Does anyone know whats goes wrong here? I searched for a couple of hours on the internet, but couldn't find any help..

1 Answer 1

1

The problem is in the error:

MassAssignmentException: name

You are trying to mass assign the variable name - but your model does not allow this.

Change your User model from this:

protected $fillable = [];

to this:

protected $fillable = ['name'];

You can read more about mass assignment here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.