OwnedPermission::billing()->edit();
/**
* returns:
* 'billing.[owned].edit'
*/
//Or, with global helper functions..
ownedPermission('billing')->read();
/**
* returns:
* 'billing.[owned].read'
*/
//Or, 'only' a subset for a specific scope..
teamPermission('billing')->only(['browse', 'edit']);
/**
* returns:
* Illuminate\Support\Collection
* {
* 'billing.[team].browse',
* 'billing.[team].edit'
* }
*/
//Or, 'except' a subset for a specific scope..
teamPermission('billing')->except(['force_delete', 'restore']);
/**
* returns:
* Illuminate\Support\Collection
* {
* 'billing.[team].browse',
* 'billing.[team].read',
* 'billing.[team].edit',
* 'billing.[team].add',
* 'billing.[team].delete',
* 'billing.[team].*'
* }
*/
//=> config/permission-name-generator
//For the quickstart, just add a couple resources
return [
'resources' => [
'user',
'billing',
'...'
],
'settings' => [
//explained in next section
'...'
]
];
//=> routes/web.php
use Jhavenz\PermissionName\Facades\OwnedPermission;
Route::get('permissions', function () {
OwnedPermission::billing()->edit();
//returns 'billing.[owned].edit'
});
//or, get all 'resources' now available to you:
Route::get('permissions', function () {
return collect([OwnedPermission::all(), TeamPermission::all()])->toArray();
});
//=> routes/web.php
//note the Facade change
use Jhavenz\PermissionName\Facades\TeamPermission;
Route::get('permissions', function () {
TeamPermission::billing()->edit();
//returns 'billing.[team].edit'
});
//=> config/permission-name-generator
return [
'resources' => [
...
],
'settings' => [
'user', //can be 'settings' related to a model in your app...
'smtp', //or any random 'settings' that your app uses..
]
];
//=> routes/web.php
//note the Facade change
use Jhavenz\PermissionName\Facades\OwnedSettingPermission;
Route::get('permissions', function () {
OwnedSettingPermission::smtp()->edit();
//returns 'smtp.[owned_setting].edit'
});
//or, get all 'settings' now available to you:
Route::get('permissions', function () {
return collect([OwnedSettingPermission::all(), TeamSettingPermission::all()])->toArray();
});
//=> routes/web.php
//note the Facade change
use Jhavenz\PermissionName\Facades\TeamSettingPermission;
Route::get('permissions', function () {
TeamSettingPermission::smtp()->edit();
//returns 'smtp.[team_setting].edit'
});
ownedPermission('billing')->read();
//returns 'billing.[owned].read'
//or
teamSettingPermission('smtp')->restore();
//returns 'smtp.[team_setting].restore'
//the 'only' and 'except' methods (explained below) can be chained here as well...
ownedSettingPermission('smtp')->only('browse', 'add', 'delete');
//returns a Illuminate\Support\Collection only containing these 3 permission strings
teamPermission('billing')->except('*', 'force_delete');
//returns a Illuminate\Support\Collection with all permissions in the 'billing.[team]' prefix,
//excluding '*' and 'force_delete'
teamSettingPermission();
//returns all 'settings' permissions within the [team_setting] scope
ownedPermission();
//return all 'resources' permissions within the [owned] scope
//etc..
//=> dashboard.blade.php (for example)
//If using Laravel Gate or something like 'Spatie Permission'
@if (Auth::user()->can(TeamPermission::profile()->browse(), $team))
User CAN browse the profile for their team
@else
User CAN NOT view the profile for their team
@endif
/*
* Global Helpers
* You can also use one of the four global helper functions
* that are available...
*/
@if (Auth::user()->can(teamPermission('profile')->browse(), $team))
User CAN browse the profile for their team
@else
User CAN NOT view the profile for their team
@endif
//or
@if (Auth::user()->can(ownedSettingPermission('smtp')->edit(), $team))
User CAN edit the their own smtp settings
@else
User CAN NOT edit the their own smtp settings
@endif
//...etc.
//You can use these methods on the 'settings' Facades as well...
OwnedSettingPermission::smtp()->only('browse', 'edit', 'delete');
// returns a Collection with:
// [
// 'smtp.[owned_setting].browse',
// 'smtp.[owned_setting].edit',
// 'smtp.[owned_setting].delete',
// ]
//or for 'team_settings'...
TeamSettingPermission::smtp()->except('browse', 'read', 'force_delete', '*');
// returns a Collection with:
// [
// 'smtp.[team_setting].add',
// 'smtp.[team_setting].edit',
// 'smtp.[team_setting].delete',
// 'smtp.[team_setting].restore',
// ]
//=> routes/web.php
use Jhavenz\PermissionName\Facades\AllPermissions;
Route::get('permissions', function () {
AllPermissions::all();
//returns a Laravel Collection of all available permissions that were generated
});
//=> routes/web.php
use Jhavenz\PermissionName\Facades\OwnedPermission;
Route::get('permissions', function () {
OwnedPermission::all();
//returns a Laravel Collection of all 'resource' permissions within the 'owned' scope
});
use Jhavenz\PermissionName\Facades\AllPermissions;
use Jhavenz\PermissionName\Facades\OwnedPermission;
use Jhavenz\PermissionName\Facades\OwnedSettingPermission;
use Jhavenz\PermissionName\Facades\TeamPermission;
use Jhavenz\PermissionName\Facades\TeamSettingPermission;
use AllPermissions;
use OwnedPermission;
//and so on..
use OwnedPermission;
use TeamPermission;
/**
* for 'resource' related items
*/
OwnedPermission::user()->delete();
//=> returns 'user.[owned].delete'
//..or
TeamPermission::billing()->wildcard();
//=> returns 'billing.[team].*'
// or any of the 'retrieval methods' (explained below)
AllPermission::all();
//This will give you a combined Laravel Collection of 'resources' and 'settings' that you've listed in your config file..
use AllPermissions;
AllPermissions::forOwned();
AllPermissions::forTeam();
AllPermissions::forOwnedSetting();
AllPermissions::forTeamSetting();
//Once you set the scope, continue chaining like any of the other Facades...
// e.g. for one of your 'resources'
AllPermissions::forOwned()->billing()->delete();
//returns 'billing.[owned].delete'
// e.g. or one of your 'settings'
AllPermissions::forTeamSetting()->smtp()->edit();
//returns 'smtp.[team_setting].edit'
use Jhavenz\PermissionName\Facades\AllPermissions;
use Jhavenz\PermissionName\Facades\OwnedPermission;
use Jhavenz\PermissionName\Facades\TeamSettingPermission;
/**
* A.
* We're in the 'owned' scope here...
*/
OwnedPermission::all();
// returns all 'resource' permissions that include '[owned]'
/**
* B.
* We're in the '[team_setting]' scope here...
*/
TeamSettingPermission::billing()->all();
// returns all '[team_settings]' permissions related to billing
/**
* C.
* Lastly...the one case were a 'scope' is not