In my routes file, I normally check against a single permission with can:manage-admin, which works fine. I read in the documentation that checking against multiple permissions can be done with permission and | to separate them such as permission:manage-admin|manage-whatever. I changed my can usaged to permission below and I am now getting an error "Class permission does not exist".
I posted my Permission.php file below the Routes below
Routes
Route::group(['middleware' => ['permission:view-user|edit-labels']], function () {
Route::post('admin/api/scan-barcode', 'Admin\UsersController@checkLabel');
});
Permissions.php
<?php
namespace App\Models\Helpers;
use App\Models\User;
class Permissions
{
/**
* The user.
*
* @var App\Models\User
*/
protected $user;
/**
* The list of all possible permissions.
*
* @return array
*/
public function __construct(User $user)
{
$this->user = $user;
}
public static function list()
{
return [
'view-user' => 'View User',
'edit-labels' => 'Edit Labels,
];
}
public static function permissionKeys()
{
return array_keys(static::list());
}
public function has($permission)
{
if ($this->user->isSuperAdmin()) {
return true;
}
if (isset($this->user->permissions['all-permissions']) && $this->user->permissions['all-permissions'] == true) {
return true;
}
if (isset($this->user->permissions[$permission]) && $this->user->permissions[$permission] == true) {
return true;
}
return false;
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire