app/Api/V1/Controllers/PermissionController.php
/**
     * Store a newly created permission in storage.
     *
     * @param PermissionRequest $request
     * @return Response
     * @throws \Illuminate\Validation\ValidationException
     */
Store a newly created permission in storage.
@param PermissionRequest $request
@return Response
@throws \Illuminate\Validation\ValidationException
Store a newly created permission in storage . @param PermissionRequest $request @return Response @throws \ Illuminate \ Validation \ ValidationException
public function store(PermissionRequest $request)
    {
        $this->validate($request, [
            'permission_name' => 'required|string'
        ]);
        $permissions = $this->generatePermissions($request->permission_name);
        foreach ($permissions as $permission) {
            Permission::query()->firstOrCreate(['name' => $permission ]);
        }
        if ($role = Role::query()->where('name', 'super_admin')->first()) {
            $role->syncPermissions(Permission::all());
        }
        return new Response(['status'=>  'Permissions ' . implode(', ', $permissions) . ' created.' ], 201);
    }
public function store ( PermissionRequest $ request ) { $ this -> validate ( $ request , [ 'permission_name' => 'required|string' ] ) ; $ permissions = $ this -> generatePermissions ( $ request -> permission_name ) ; foreach ( $ permissions as $ permission ) { Permission :: query ( ) -> firstOrCreate ( [ 'name' => $ permission ] ) ; } if ( $ role = Role :: query ( ) -> where ( 'name' , 'super_admin' ) -> first ( ) ) { $ role -> syncPermissions ( Permission :: all ( ) ) ; } return new Response ( [ 'status' => 'Permissions ' . implode ( ', ' , $ permissions ) . ' created.' ] , 201 ) ; }
Store a newly created permission in storage.
Store a newly created permission in storage .
// create permissions // sync role for super_admin