yaroslawww / laravel-restricted-access
This package is abandoned and no longer maintained.
The author suggests using the think.studio/laravel-restricted-access package instead.
Restrict access to any entities or pages, or create share links.
1.2.0
2023-07-18 12:46 UTC
Requires
- php: ^8.1
- illuminate/support: ^9.0|^10.0
- think.studio/laravel-json-field-cast: ^2.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.20
- orchestra/testbench: ^8.5
- phpunit/phpunit: ^10.2
- psalm/plugin-laravel: ^2.8
- vimeo/psalm: ^5.13
README
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