Policy Last updated: 2023-09-30

We know that Policies are important in the roles of administrators

Additionally, in our dash project 

We have added groups and roles tables and also created a master policy object


with Models (App\Models\AdminGroup.php,App\Models\AdminGroupRole.php) also 

we have also added the resources AdminGroups and AdminGroupRoles in Dash\Resources path

Everything is ready and all you have to do is to add any new resource to the permissions in App\Dash\Resources\AdminGroupRoles in the option method 

select()->make('resource', 'resource')
	->rule('required', 'string)->ruleWhenCreate(
	Rule::unique('admin_group_roles')->where(function ($q) {
		$q->where('resource', request('resource'));
		$q->where('admin_group_id', request('admingroup'));
	'users' => 'Users',
	'admin_groups' => 'AdminGroups',
	'admin_group_role' => 'AdminGroupRoles',


We will see that it is associated with three types of resources Users & AdminGroups & AdminGroupRoles 

If we want to add the Articles resource in the permissions , we can do the following

	'users' => 'Users',
	'admin_groups' => 'AdminGroups',
	'admin_group_role' => 'AdminGroupRoles',


If you want to activate this permission with the articles resource

You need to create a new policy using dash command 

php artisan dash:make-policy ArticlePolicy


if you want to create policy in Modules Path you can use --module= flag

php artisan dash:make-policy ArticlePolicy --module=Articles


file created in app/Policies path

namespace App\Policies;
use Dash\Policies\Policy;

class ArticlePolicy extends Policy {
	protected $resource = 'articles';

Remember that you want to add the key in $resource  property 

protected $resource = 'articles';


Then you can add the policy to the resource Articles


namespace App\Dash\Resources;
use Dash\Resource;

class Articles extends Resource {
	 * Policy Permission can handel
	 * (viewAny,view,create,update,delete,forceDelete,restore) methods
	 * @param static property as Policy Class
	public static $policy = \App\Policies\ArticlePolicy::class ;


Then you can add the value in the database through the example.com/dash/AdminGroupRoles



If you want to know more about  how policies work based on the base object , see the abstract class