1. Go to this page and download the library: Download laravelplus/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/ */
laravelplus / fortress example snippets
use Laravelplus\Fortress\Attributes\Authorize;
class PostController
{
#[Authorize(
public: false,
roles: ['admin', 'editor'],
permissions: ['create', 'update'],
owner: App\Models\Post::class,
overrideKey: 'author_id'
)]
public function update(Request $request, $id)
{
// Update logic
}
}
#[Authorize(public: true)]
public function show($id)
{
// This method is accessible by everyone
}
#[Authorize(roles: ['manager'], permissions: ['approve-leave'])]
public function approveLeave(Request $request)
{
// This method is accessible only by managers with approve-leave permission
}
#[Authorize(owner: App\Models\Comment::class, overrideKey: 'user_id')]
public function editComment(Request $request, $id)
{
// Accessible only if the comment belongs to the authenticated user
}
#[Authorize(gates: 'edit-settings')]
public function settings()
{
// This method is accessible if the "edit-settings" gate returns true
}