Inheritance: extends Illuminate\Database\Eloquent\Model
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     /**
      * ADMIN ROLES
      *
      */
     $createUser = new PermissionRole();
     $createUser->role_id = '1';
     $createUser->permission_id = '1';
     $createUser->timestamps = false;
     $createUser->save();
     $updateUser = new PermissionRole();
     $updateUser->role_id = '1';
     $updateUser->permission_id = '2';
     $updateUser->timestamps = false;
     $updateUser->save();
     $deleteUser = new PermissionRole();
     $deleteUser->role_id = '1';
     $deleteUser->permission_id = '3';
     $deleteUser->timestamps = false;
     $deleteUser->save();
     $createClient = new PermissionRole();
     $createClient->role_id = '1';
     $createClient->permission_id = '4';
     $createClient->timestamps = false;
     $createClient->save();
     $updateClient = new PermissionRole();
     $updateClient->role_id = '1';
     $updateClient->permission_id = '5';
     $updateClient->timestamps = false;
     $updateClient->save();
     $deleteClient = new PermissionRole();
     $deleteClient->role_id = '1';
     $deleteClient->permission_id = '6';
     $deleteClient->timestamps = false;
     $deleteClient->save();
     $createTask = new PermissionRole();
     $createTask->role_id = '1';
     $createTask->permission_id = '7';
     $createTask->timestamps = false;
     $createTask->save();
     $updateTask = new PermissionRole();
     $updateTask->role_id = '1';
     $updateTask->permission_id = '8';
     $updateTask->timestamps = false;
     $updateTask->save();
     $createLead = new PermissionRole();
     $createLead->role_id = '1';
     $createLead->permission_id = '9';
     $createLead->timestamps = false;
     $createLead->save();
     $updateLead = new PermissionRole();
     $updateLead->role_id = '1';
     $updateLead->permission_id = '10';
     $updateLead->timestamps = false;
     $updateLead->save();
 }
Ejemplo n.º 2
0
 protected function create($values)
 {
     $data = [];
     foreach ($this->structure as $i => $key) {
         $data[$key] = $values[$i];
     }
     PermissionRole::create($data);
 }
 public function lastUpdated()
 {
     $query = PermissionRole::orderBy('updated_at', 'DESC')->first();
     if ($query) {
         return $query->updated_at->format('Y-m-d H:i:s');
     }
     return date("Y-m-d H:i:s");
 }
Ejemplo n.º 4
0
 public function getPermissionRole()
 {
     $query = \App\Models\PermissionRole::query()->where('role_id', $this->id)->get();
     $results = [];
     foreach ($query as $key => $val) {
         $results[$key] = $val->permission->slug_view;
     }
     return $results;
 }
Ejemplo n.º 5
0
 public function run()
 {
     DB::table('permission_role')->truncate();
     $permission_role = [];
     $permissions = Permission::get();
     $role = Role::find(1);
     foreach ($permissions as $key => $value) {
         $permission_role[] = ['permission_id' => $value->id, 'role_id' => $role->id, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")];
     }
     PermissionRole::insert($permission_role);
 }
 /**
  * Update the specified PermissionRole in storage.
  *
  * @param  int    $id
  * @param Request $request
  *
  * @return Response
  */
 public function bulkUpdate(Request $request)
 {
     $input = $request->all();
     $role_id = isset($input['role_id']) ? $input['role_id'] : false;
     if (isset($input['is_create']) && $input['is_create']) {
         if (sizeof(Role::$rules) > 0) {
             $this->validateRequest($request, Role::$rules);
         }
         $input = $request->all();
         $role = $this->roleRepository->create($input);
         $role_id = $role->id;
     }
     if (!isset($input['data']) || !$role_id) {
         $this->throwRecordNotFoundException("PermissionRole not found", ERROR_CODE_RECORD_NOT_FOUND);
     }
     foreach ($input['data'] as $key => $data) {
         $permissionRole = PermissionRole::where('role_id', $role_id)->where('permission_id', $data['permission_id'])->first();
         /*
          **	If empty and it's true, Insert new permission
          */
         if (!$permissionRole && $data['value'] == true) {
             $permission['role_id'] = $role_id;
             $permission['permission_id'] = $data['permission_id'];
             $this->permissionRoleRepository->create($permission);
             continue;
         }
         /*
          ** If exist and it's false, Delete the permission
          */
         if ($permissionRole && $data['value'] == false) {
             $this->permissionRoleRepository->delete($permissionRole->id);
         }
     }
     $current_permission = PermissionRole::where('role_id', $role_id)->get();
     $meta = array('total' => count($current_permission), 'count' => count($current_permission), 'offset' => 0, 'last_updated' => $this->permissionRoleRepository->lastUpdated(), 'status' => "PermissionRole updated successfully.", 'error' => 'Success');
     return Response::json(ResponseManager::makeResult($current_permission->toArray(), $meta), 201);
 }