Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-static method is() Execption #16

Closed
ndberg opened this issue Dec 3, 2015 · 4 comments
Closed

Non-static method is() Execption #16

ndberg opened this issue Dec 3, 2015 · 4 comments
Labels

Comments

@ndberg
Copy link

ndberg commented Dec 3, 2015

I have a basic Problem with checking if a user has a role:

If I do it in routes.php it works:

        $user = User::find(3);
        Bouncer::is($user)->a('admin');

If i do it in the CompanyController, I get this Error:

at HandleExceptions->handleError('8192', 'Non-static method Silber\Bouncer\Bouncer::is() should not be called statically, assuming $this from incompatible context', '/home/vagrant/Code/torebuild1/app/Http/Controllers/CompanyController.php', '112', array('id' => '3', 'user' => object(User))) in CompanyController.php line 112

Is there a Issue or am I doing something completely wrong?

@JosephSilber
Copy link
Owner

All examples in the docs use the facade. If you've set up the facade alias, you should be able to use the examples in the docs directly. Do not use Silber\Bouncer\Bouncer.

If you don't want to use the facade, inject an instance of Bouncer into your controller:

public function foo(Bouncer $bouncer)
{
    $bouncer->is($user)->an('admin');
}

If you go down this path, do use Silber\Bouncer\Bouncer.

@ndberg
Copy link
Author

ndberg commented Dec 3, 2015

If I take the use Silber\Bouncer\Bouncer out of the Controller then I have the Error:

Class 'App\Http\Controllers\Bouncer' not found

But I did follow the Installation Instructions, means: I did add the Lines to the providers and to the aliases array in config/app.php.

@JosephSilber
Copy link
Owner

Add this instead:

use Bouncer;

This'll import the global facade alias.

@ndberg
Copy link
Author

ndberg commented Dec 3, 2015

Ah great, thank you very much.. Now it works..

I've been searching for hours about this issue..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants