1. Go to this page and download the library: Download lbausch/laravel-fortress 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/ */
lbausch / laravel-fortress example snippets
...
use Bausch\LaravelFortress\Contracts\FortressGuardContract;
use Bausch\LaravelFortress\Traits\FortressGuardTrait as FortressGuard;
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract,
FortressGuardContract
{
use Authenticatable, Authorizable, CanResetPassword, FortressGuard;
...
...
/**
* Fortress Relations.
*
* @return \Illuminate\Support\Collection
*/
public function fortress_relations()
{
return $this->groups;
}
/**
* Groups.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function groups()
{
return $this->belongsToMany(Group::class, 'group_members');
}
...
/*
* Define Roles here which do not apply to a specific Resource.
*
* role_name => [permissions]
*/
return [
'admin' => [
'broadcast',
'manageUsers',
],
];
...
use Bausch\LaravelFortress\Contracts\FortressPolicy;
class BlogPolicy implements FortressPolicy
{
/**
* Fortress Roles.
*
* @return array
*/
public function fortress_roles()
{
return [
'owner' => [
'edit',
'destroy',
],
];
}
...
$readable_blogs = $user->myAllowedResources('read', Blog::class, function($resources) {
// $resources contains a Collection of all found Resources
return Blogs::whereIn('id', $resources->pluck('resource_id'));
});