1. Go to this page and download the library: Download uzzal/acl library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Uzzal\Acl\Traits\AccessControlled;
class User extends Authenticatable
{
use AccessControlled;
...
}
#[Authorize('Admin, Default')] // string
#[Resource('able to see home')]
public function index()
{
return view('home');
}
// or alternatively
#[Authorize('Admin', 'Default')] // array
#[Resource('able to see home')]
public function index()
{
return view('home');
}
Route::group(['middleware' => ['resource.maker','auth.acl']], function () {
Route::get('/home', 'HomeController@index');
});
if (allowed('home.index')) {
echo "will allow here if the user has access";
}
// alternatively in blade template
@allowed('home.index')
<h4>Will be visible if the user has permission</h4>
@endallowed
if (allowed([\App\Http\Controllers\HomeController::class, 'index'])) {
echo "will allow here if the user has access";
}
// alternatively in blade template
@allowed([\App\Http\Controllers\HomeController::class, 'index'])
<h4>Will be visible if the user has permission</h4>
@endallowed
if (allowedAny(['Home','Profile'])) {
echo "Will be visible if the user has permission for any action of Home and Profile controller";
}
// alternatively in blade template
@allowedAny(['Home','Profile'])
<h4>Will be visible if the user has permission for any action of Home and Profile controller</h4>
@endallowedAny
// for single controller it can be written like this
@allowedAny('Home')
<h4>Will be visible if the user has permission for any action of Home Controller</h4>
@endallowedAny
if (hasRole(['Admin','Editor'])) {
echo "Will be visible if the user has Admin or Editor or both roles";
}
// alternatively in blade template
@hasRole(['Admin','Editor'])
<h4>Will be visible if the user has Admin or Editor or both roles</h4>
@endhasRole
// for single Role it can be written like this
@hasRole('Admin')
<h4>Will be visible if the user has Admin roles</h4>
@endhasRole
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.