laravel-restricted-access maintained by yaroslawww
Description
Restrict access to any entities or pages, or create share links.
Author
Last update
2023/07/18 14:46
(dev-main)
License
Downloads
6
Tags
Restrict access to any entities or pages, or create share links.
Restrict access for pages, with pin code, email or name.
Installation
Install the package via composer:
composer require think.studio/laravel-restricted-access
Optionally you can publish the config file with:
php artisan vendor:publish --provider="LinkRestrictedAccess\ServiceProvider" --tag="config"
If you want change tables names or routes, you can do it via config file.
Run migrations:
php artisan migrate
Usage
Use trait HasRestrictedLink for model
class File extends Model
{
use \LinkRestrictedAccess\Models\HasRestrictedLink;
}
Then you can create link
/** @var RestrictedLink $shareLink */
$shareLink = $file->restrictedLinks()->make([
'name' => $request->input('name'),
'pin' => $request->input('pin'),
'check_pin' => $request->boolean('check_pin'),
'check_name' => $request->boolean('check_name'),
'check_email' => $request->boolean('check_email'),
]);
if ($user = $request->user()) {
$shareLink->meta->toMorph('creator', $user);
}
$shareLink->save();
Example check verification.
if($shareUuid = $request->string('share')) {
$sharedLink = \LinkRestrictedAccess\RestrictedAccess::restrictedLinkModel()::query()->byKey($shareUuid)->firstOrFail();
if ($sharedLink->needVerification() && !$sharedLink->verifiedOpenActionFromCookie($request)) {
return // display verification view
}
return $sharedLink->linkable;
}
To verify access you can use routes restricted-access-link.check-pin and restricted-access-link.open-document



