1. Go to this page and download the library: Download evansims/openfga-laravel 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/ */
declare(strict_types=1);
use App\Models\Document;
class DocumentController extends Controller
{
/**
* Share a document with another user.
*/
public function share(Request $request, Document $document): RedirectResponse
{
// Ensure user can share (only owners can share)
$this->authorize('owner', $document);
// Grant permission to new user
$document->grant($request->user_email, $request->permission);
return back()->with('success', 'Document shared successfully!');
}
/**
* List documents the user can view.
*/
public function index(): View
{
$documents = Document::whereUserCan(auth()->user(), 'viewer')
->latest()
->paginate();
return view('documents.index', compact('documents'));
}
}