laravel-5-roles-and-permissions-demo
laravel-5-roles-and-permissions-demo copied to clipboard
ERROR: select * from `permissions`
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.
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?
Just catch the PDOException
in your service provider:
https://github.com/larapacks/authorization/blob/master/src/AuthorizationServiceProvider.php#L60
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
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);
});
}
}
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...
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 >