Inheritance: extends Illuminate\Database\Eloquent\Model, use trait Spatie\Permission\Traits\HasPermissions, use trait Spatie\Permission\Traits\RefreshesPermissionCache
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $roles = config('webegg.roles');
     $actions = config('webegg.actions');
     $types = config('webegg.models');
     foreach ($roles as $r) {
         Role::create(['name' => $r]);
     }
     $permissions = array_reduce($actions, function ($perms, $action) use($types) {
         return $perms + array_map(function ($type) use($action) {
             return Permission::create(['name' => "{$action} {$type}"]);
         }, $types);
     }, []);
     foreach (Permission::all() as $p) {
         Role::findByName('admin')->givePermissionTo($p->name);
     }
 }
Exemplo n.º 2
1
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $name = $this->argument('name');
     Role::create(['name' => $name]);
     $this->comment("Created a new role named: " . $name . PHP_EOL);
 }
Exemplo n.º 3
0
 /**
  * Remove the specified Fascie from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $role = Role::where('id', $id)->first();
     $role->permissions()->sync([]);
     $role->delete();
     return 'true';
 }
Exemplo n.º 4
0
 public function store(RoleFormRequest $request)
 {
     $id = mt_rand(5, 15);
     $role = Role::create(['ID' => $id, 'NAME' => $request->get('role')]);
     $role->givePermissionTo('Create Order');
     $role->save();
     return redirect('/dashboard')->with('status', 'Done added role');
 }
Exemplo n.º 5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $feature = $this->option('feature');
     $role = $this->option('role');
     $role = Role::where('name', strtolower($role))->first();
     $role->givePermissionTo(strtolower($feature));
     $this->comment("All " . $role->name . "(s) have permissions to " . $feature . PHP_EOL);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function dashboard()
 {
     $users = \App\User::all()->count();
     $roles = \Spatie\Permission\Models\Role::all()->count();
     $permissions = \Spatie\Permission\Models\Permission::all()->count();
     $entities = \Amranidev\ScaffoldInterface\Models\Scaffoldinterface::all();
     return view('scaffold-interface.dashboard.dashboard', compact('users', 'roles', 'permissions', 'entities'));
 }
Exemplo n.º 7
0
 protected function asAnAdminUser()
 {
     $role = \Spatie\Permission\Models\Role::create(['name' => 'admin']);
     $user = factory(User::class)->create();
     factory(\App\Profile::class)->create(['user_id' => $user->id]);
     $user->assignRole($role);
     $this->actingAs($user);
 }
Exemplo n.º 8
0
 /**
  * Run the database seeds.
  */
 public function run()
 {
     // php artisan db:seed --class="RolesTableSeeder"
     $roles = [['name' => 'admin'], ['name' => 'editor']];
     foreach ($roles as $role) {
         Role::create($role);
     }
 }
Exemplo n.º 9
0
 public function roleList()
 {
     $roleListArray = [];
     $roles = Role::select('id', 'name')->get();
     foreach ($roles as $role) {
         $roleListArray[$role->name] = ucfirst($role->name);
     }
     return $roleListArray;
 }
Exemplo n.º 10
0
 public function validate_role($role_string)
 {
     if (!in_array($role_string, $this->allowed_roles)) {
         return false;
     }
     $role = Role::where('name', $role_string)->first();
     if (!$role) {
         return false;
     }
     return $role_string;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $role = \Spatie\Permission\Models\Role::create(['name' => 'admin']);
     $user = factory(\App\User::class)->create(['email' => '*****@*****.**', 'password' => 'password']);
     $user->assignRole($role);
     $user->addProfile();
     $user->profile->addGallery('my images');
     $user2 = factory(\App\User::class)->create(['email' => '*****@*****.**', 'password' => 'password']);
     $user2->addProfile();
     $user2->profile->addGallery('my images');
 }
Exemplo n.º 12
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $currentUser = $this->user->find(Auth::id());
     $currentRole = current(current($currentUser->roles));
     $listIds = explode(",", $id);
     foreach ($listIds as $item) {
         if ($currentRole->id != $item) {
             $this->role->destroy($item);
         }
     }
     return response()->json(['result' => 'Success'], 200);
 }
 /**
  * Create Roles and Permissions
  */
 public function up()
 {
     //
     // Roles
     //
     // Superadministrator
     Role::create(['name' => 'superadmin']);
     // Admin
     Role::create(['name' => 'admin']);
     // Organizer
     Role::create(['name' => 'organizer']);
     //
     // Permissions
     //
     // Create events
     Permission::create(['name' => 'create events']);
     // Create organizers
     Permission::create(['name' => 'create organizers']);
     // Create organizers
     Permission::create(['name' => 'create users']);
     //
     // Attach Permission to Roles.
     //
     // Superadmin
     Role::findByName('superadmin')->givePermissionTo('create users')->givePermissionTo('create events')->givePermissionTo('create organizers');
     // Admin
     Role::findByName('admin')->givePermissionTo('create users')->givePermissionTo('create events')->givePermissionTo('create organizers');
     // Organizer
     Role::findByName('organizer')->givePermissionTo('create events');
     // Create Admin User
     $user = new User();
     $user->name = "Pascale Beier";
     $user->email = "*****@*****.**";
     $user->password = bcrypt("P@scale1993");
     $user->save();
     $user->assignRole('admin');
     // Create Superadmin User
     $user = new User();
     $user->name = "superadmin";
     $user->email = "*****@*****.**";
     $user->password = bcrypt("superadmin");
     $user->save();
     $user->assignRole('superadmin');
     // Create Organizer User
     $user = new User();
     $user->name = "organizer";
     $user->email = "*****@*****.**";
     $user->password = bcrypt("organizer");
     $user->save();
     $user->assignRole('organizer');
 }
Exemplo n.º 14
0
 /**
  * Run the database seeds.
  */
 public function run()
 {
     // php artisan db:seed --class="PermissionRoleTableSeeder"
     $permissions = Permission::all();
     $adminRole = Role::whereName('admin')->first();
     foreach ($permissions as $permission) {
         if (!$adminRole->hasPermissionTo($permission)) {
             $adminRole->givePermissionTo($permission->name);
         }
     }
     $rolePermissions = ['manage_pages', 'access_admin'];
     /** @var Role $editorRole */
     $editorRole = Role::whereName('editor')->first();
     foreach ($rolePermissions as $permission) {
         if (!$editorRole->hasPermissionTo($permission)) {
             $editorRole->givePermissionTo($permission);
         }
     }
 }
Exemplo n.º 15
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $name = $this->ask('Name');
     $check = true;
     while ($check == true) {
         $email = $this->ask('Email');
         $check = User::where('email', '=', $email)->exists();
         if ($check) {
             $this->error('Email already exists, try again.');
         }
     }
     $password = $this->secret('Password');
     $admin_role = $this->ask('Role [admin]') ?: 'admin';
     if ($this->confirm('Do you wish to setup this user? [y|N]')) {
         $_user = User::create(['name' => $name, 'email' => $email, 'password' => bcrypt($password)]);
         if (!Role::where('name', '=', $admin_role)->exists()) {
             $_role = Role::create(['name' => $admin_role]);
         }
         $_user->assignRole($admin_role);
     }
 }
Exemplo n.º 16
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Role::create(['name' => 'admin']);
     Role::create(['name' => 'user']);
 }
Exemplo n.º 17
0
 /**
  * @param $role
  *
  * @return Role
  */
 protected function getStoredRole($role)
 {
     if (is_string($role)) {
         return Role::findByName($role);
     }
     return $role;
 }
Exemplo n.º 18
0
 /**
  * Show the form for editing the specified User.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id, InternalUsersRepo $internal_users_repo)
 {
     $utente = $internal_users_repo->getById($id);
     $ruoli = Role::all();
     return view('admin.acl.utenti.edit', compact('utente', 'ruoli'));
 }
Exemplo n.º 19
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $admin = User::create(['name' => 'admin', 'email' => '*****@*****.**', 'password' => bcrypt('password'), 'created_at' => date("Y-m-d"), 'updated_at' => date("Y-m-d")]);
     $role = Role::create(['name' => 'admin']);
     $admin->assignRole('admin');
 }
Exemplo n.º 20
0
 /**
  * Create user form
  *
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function create()
 {
     $roles = Role::lists('name', 'id')->toArray();
     return view('backend.user.create', compact('roles'));
 }
Exemplo n.º 21
0
 public function rolesOptions()
 {
     return Role::all()->pluck('name', 'name')->toArray();
 }
Exemplo n.º 22
0
 /**
  * @test
  */
 public function it_wont_delete_the_final_user()
 {
     $user1 = factory('App\\User')->create();
     $role = \Spatie\Permission\Models\Role::create(['name' => 'admin']);
     $user1->assignRole($role);
     $this->withoutMiddleware();
     $this->actingAs($user1);
     $this->call('DELETE', '/admin/users/' . $user1->id);
     $this->seeInDatabase('users', ['id' => $user1->id, 'name' => $user1->name, 'email' => $user1->email]);
 }
Exemplo n.º 23
0
 /**
  * Remove the specified resource from storage.
  *
  * @param int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $role = Role::findOrFail($id);
     $role->delete();
     return redirect('roles');
 }