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

ERROR: select * from permissions #8

Open
brainm opened this issue May 25, 2016 · 6 comments
Open

ERROR: select * from permissions #8

brainm opened this issue May 25, 2016 · 6 comments

Comments

@brainm
Copy link

brainm commented May 25, 2016

This code in file app/Providers/AuthServiceProvider.php

        foreach ($this->getPermissions() as $permission) {
            $gate->define($permission->name, function ($user) use ($permission) {
                return $user->hasPermission($permission);
            });
        }                                                                                                                     

return errors when you deploy project

  [Illuminate\Database\QueryException]                                                                               
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'xxx.permissions' doesn't exist (SQL: select * from  
   `permissions`)  
  [PDOException]                                                                                 
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'xxx.permissions' doesn't exist  

You have to comment this php code lines, execute php artisan migrate and uncomment back.

@gabrielgagno
Copy link

I am also experiencing this issue. I think it tries to read AuthServiceProvider first before doing the normal php artisan procedure. Has anyone found a solution to this?

@stevebauman
Copy link

Just catch the PDOException in your service provider:

https://github.com/larapacks/authorization/blob/master/src/AuthorizationServiceProvider.php#L60

@brainm
Copy link
Author

brainm commented Aug 26, 2016

isko-algorithm, solution is to cut off this lines:

        foreach ($this->getPermissions() as $permission) {
            $gate->define($permission->name, function ($user) use ($permission) {
                return $user->hasPermission($permission);
            });
        }         

run

$:~ php artisan migrate

and insert back this lines on it place

@ghost
Copy link

ghost commented Jan 1, 2017

use Illuminate\Support\Facades\Schema;

    if (Schema::hasTable('permissions')) {
        // Dynamically register permissions with Laravel's Gate.
        foreach ($this->getPermissions() as $permission) {
            $gate->define($permission->name, function ($user) use ($permission) {
                return $user->hasPermission($permission);
            });
        }
    }

@Aushraful
Copy link

use Illuminate\Support\Facades\Schema;

    if (Schema::hasTable('permissions')) {
        // Dynamically register permissions with Laravel's Gate.
        foreach ($this->getPermissions() as $permission) {
            $gate->define($permission->name, function ($user) use ($permission) {
                return $user->hasPermission($permission);
            });
        }
    }

What an awesome find... Just check for the table before accessing it...

@yiiman-dev
Copy link

yiiman-dev commented Nov 17, 2021

check
if (empty($_SERVER['argv']))

so, when you are using console $_SERVER['argv'] is like this:

$argv=
[
    'artisan'
];

you should change your auth provider like this:

        // < Disable auth in console >
        {
            if (empty($_SERVER['argv'])) {
                foreach (Permission::all() as $permission) {
                    Gate::define($permission->name, function ($user) use ($permission) {
                        return $user->employee->hasAccess($permission);
                    });

                }
            }
        }
        // </ Disable auth in console >

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

No branches or pull requests

5 participants