Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maymeow's avatar

Testing roles and permissions stored in database

Hi all.. I have implemented roles and permission from laracasts (5.4 laravel from scratch) Where Roles and permissions are stored in database.

When i try to test hasRole() Function i getting error about Call to undefined method Illuminate\Database\Query\Builder::contains() not exists.

Here is this function https://github.com/gitcity-sk/webapp-ce/blob/25-create-cms/app/Traits/RolesTrait.php

test:

/** @test */
    public function users_can_see_single_project()
    {
        $role = factory(Role::class)->create(['name' => 'administrator']);
        $showPerm = factory(Permission::class)->create(['name' => 'show-project']);
        $delPerm = factory(Permission::class)->create(['name' => 'delete-project']);
        $role->givePermissionTo($showPerm);
        $role->givePermissionTo($delPerm);
        $this->user->assignRole($role->name);

        $this->user->hasRole($role->name);

        $response = $this->actingAs($this->user)
        ->get('/projects/' . $this->project->id);
        $response->assertStatus(403);
    }

Any ideas?

0 likes
0 replies

Please or to participate in this conversation.