Answer the question
In order to leave comments, you need to log in
How to control access levels for Admin Architect - Laravel 5.2 modules?
I made an admin panel in Admin Architect, but I have no idea how to prohibit a certain group of users from accessing certain modules.
Usually Middleware is used for this, but the problem is that the admin routes are too abstract:
<?php
$pattern = '[a-z0-9\_\=]+';
Route::group([
'prefix' => 'area',
'namespace' => 'Terranet\Administrator',
'middleware'=> ['web'],
], function () use ($pattern) {
/*
|-------------------------------------------------------
| Authentication
|-------------------------------------------------------
*/
Route::get('login', [
'as' => 'scaffold.login',
'uses' => '[email protected]',
]);
Route::post('login', '[email protected]');
Route::get('logout', [
'as' => 'scaffold.logout',
'uses' => '[email protected]',
]);
/*
|-------------------------------------------------------
| Main Scaffolding routes
|-------------------------------------------------------
*/
Route::group(['prefix' => 'admin',], function () use ($pattern) {
/*
|-------------------------------------------------------
| Custom routes
|-------------------------------------------------------
|
| Controllers that shouldn't be handled by Scaffolding controller
| goes here.
|
*/
// Route::controllers([
// 'test' => 'App\Http\Controllers\Admin\TestController'
// ]);
/*
|-------------------------------------------------------
| Scaffolding routes
|-------------------------------------------------------
*/
// Dashboard
Route::get('/', [
'as' => 'scaffold.dashboard',
'uses' => '[email protected]',
]);
// Index
Route::get('{module}', [
'as' => 'scaffold.index',
'uses' => '[email protected]',
])->where('module', $pattern);
// Create new Item
Route::get('{module}/create', [
'as' => 'scaffold.create',
'uses' => '[email protected]',
])->where('module', $pattern);
//и т.д.
});
});
<?php
namespace App\Http\Terranet\Administrator\Modules;
use Terranet\Administrator\Contracts\Module\Editable;
use Terranet\Administrator\Contracts\Module\Exportable;
use Terranet\Administrator\Contracts\Module\Filtrable;
use Terranet\Administrator\Contracts\Module\Navigable;
use Terranet\Administrator\Contracts\Module\Sortable;
use Terranet\Administrator\Contracts\Module\Validable;
use Terranet\Administrator\Resource;
use Terranet\Administrator\Traits\Module\AllowFormats;
use Terranet\Administrator\Traits\Module\HasFilters;
use Terranet\Administrator\Traits\Module\HasForm;
use Terranet\Administrator\Traits\Module\HasSortable;
use Terranet\Administrator\Traits\Module\ValidatesForm;
/**
* Administrator Resource Accounts
*
* @package Terranet\Administrator
*/
class Accounts extends Resource implements Navigable, Filtrable, Editable, Validable, Sortable, Exportable
{
use HasFilters, HasForm, HasSortable, ValidatesForm, AllowFormats;
/**
* The module Eloquent model
*
* @var string
*/
protected $model = 'reg2005\\PayAssetsLaravel\\Entities\\Accounts';
public function __construct()
{
$this->middleware('OnlyCli');
}
}
$this->middleware('OnlyRoot', ['only' => ['canEdit', 'canDelete'] ] );
Answer the question
In order to leave comments, you need to log in
Good afternoon!
I immediately apologize for the long silence.
I will try to answer your questions briefly, but meaningfully.
At the moment, you can manage access in 2 ways:
file `config/administrator.php` contains the `permission` key, where you can specify global access levels to the admin area as a whole.
'permission' => function ()
{
return ($auth = auth('admin')->user()) && $auth->isSuperAdmin();
},
public function canEdit(Authenticatable $who, $model)
{
return $user->isSuperAdmin() && ! $model->isProtected();
}
public function canEdit(Authenticatable $user, $model)
{
return (new ACLGate($user))->forEntity($model)->checkPermission('edit');
}
public function __call($method, $args)
{
if (in_array($method, ['canEdit', 'canActivate', 'canLock'])) {
list($user, $model) = each($args);
return $user->isSuperAdmin() && ! $model->isProtected();
}
return false;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question