laravel-5-roles-and-permissions-demo icon indicating copy to clipboard operation
laravel-5-roles-and-permissions-demo copied to clipboard

ERROR: select * from `permissions`

Open brainm opened this issue 8 years ago • 6 comments

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.

brainm avatar May 25 '16 17:05 brainm

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?

gabrielgagno avatar Aug 21 '16 16:08 gabrielgagno

Just catch the PDOException in your service provider:

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

stevebauman avatar Aug 25 '16 17:08 stevebauman

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

brainm avatar Aug 26 '16 06:08 brainm

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);
            });
        }
    }

ghost avatar Jan 01 '17 13:01 ghost

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...

Aushraful avatar Jun 16 '19 12:06 Aushraful

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 >


yiiman-dev avatar Nov 17 '21 14:11 yiiman-dev