public function setupFoundorAndBaseRolsPermission() { // Create Roles $founder = new App\Role(); $founder->name = 'Founder'; $founder->save(); $admin = new App\Role(); $admin->name = 'Admin'; $admin->save(); // Create User $user = App\User::create(['github_id' => 1, 'github_url' => 'goodgoto.com', 'name' => 'summerblue']); // Attach Roles to user $user->roles()->attach($founder->id); // Create Permissions $manageTopics = new App\Permission(); $manageTopics->name = 'manage_topics'; $manageTopics->display_name = 'Manage Topics'; $manageTopics->save(); $manageUsers = new App\Permission(); $manageUsers->name = 'manage_users'; $manageUsers->display_name = 'Manage Users'; $manageUsers->save(); // Assign Permission to Role $founder->perms()->sync([$manageTopics->id, $manageUsers->id]); $admin->perms()->sync([$manageTopics->id]); }
/** * Run the database seeds. * * @return void */ public function run() { $admin = new \App\Role(); $admin->name = 'admin'; $admin->display_name = 'Administrador'; // optional $admin->description = 'Administrador de permisos del sitio'; // optional $admin->save(); $driver = new \App\Role(); $driver->name = 'driver'; $driver->display_name = 'Conductor'; // optional $driver->description = 'Conductor de las unidades'; // optional $driver->save(); $accountant = new \App\Role(); $accountant->name = 'accountant'; $accountant->display_name = 'Contador'; // optional $accountant->description = 'Encargado de la autorización de los viajes'; // optional $accountant->save(); $user = \App\User::create(['username' => 'adminadhl', 'name' => 'Administrador', 'password' => bcrypt('123456'), 'email' => '*****@*****.**']); $user2 = \App\User::create(['username' => 'chofer1', 'name' => 'Chofer #1', 'password' => bcrypt('123456'), 'email' => '*****@*****.**']); $user3 = \App\User::create(['username' => 'contador1', 'name' => 'Contador #1', 'password' => bcrypt('123456'), 'email' => '*****@*****.**']); $user->attachRole($admin); }
/** * Run the database seeds. * * @return void */ public function run() { $create = ['admin', 'staff', 'guest']; foreach ($create as $key => $value) { $roles = new App\Role(); $roles->role = $value; $roles->save(); } }
/** * Run table seeds. */ public function run() { $roles = [['name' => 'Admin', 'level' => 1], ['name' => 'Moderator', 'level' => 2], ['name' => 'User', 'level' => 3]]; foreach ($roles as $role) { $roleModel = new \App\Role(); $roleModel->name = $role['name']; $roleModel->level = $role['level']; $roleModel->save(); } }
/** * Run the database seeds. * * @return void */ public function run() { foreach (Config('predefined.roles-and-perms.Roles') as $name => $label) { $role = new \App\Role(); switch (is_numeric($name)) { case false: $role->name = $name; $role->label = $label; break; case true: $role->name = $label; break; } $role->created_at = \Carbon\Carbon::now(); $role->save(); $this->grantPermissions($role); } }
/** * Run the database seeds. * * @return void */ public function run() { $admin = new \App\Role(); $admin->name = 'admin'; $admin->display_name = 'Administrator'; $admin->save(); \App\User::all()->first()->attachRole($admin); $super = new \App\Role(); $super->name = 'supervisor'; $super->display_name = 'Supervisor'; $super->save(); $member = new \App\Role(); $member->name = 'member'; $member->display_name = 'Member'; $member->save(); \App\User::where('id', '=', 2)->first()->attachRole($member); \App\User::where('id', '=', 3)->first()->attachRole($member); }
/** * Run the database seeds. * * @return void */ public function run() { $admin = new \App\Role(); $admin->name = 'admin'; $admin->display_name = 'Administrator'; $admin->save(); $super = new \App\Role(); $super->name = 'supervisor'; $super->display_name = 'Supervisor'; $super->save(); $member = new \App\Role(); $member->name = 'member'; $member->display_name = 'Member'; $member->save(); \App\User::find(1)->attachRole($admin); \App\User::find(2)->attachRole($admin); \App\User::find(3)->attachRole($super); \App\User::find(4)->attachRole($member); }
/** * Run the migrations. * * @return void */ public function up() { Schema::create('roles', function (Blueprint $table) { $table->increments('id'); $table->string('title'); }); Schema::create('users_roles_rel', function (Blueprint $table) { $table->integer('user_id')->unsigned(); $table->integer('role_id')->unsigned(); $table->foreign('user_id')->references('id')->on('users'); $table->foreign('role_id')->references('id')->on('roles'); }); $adminRole = new \App\Role(["title" => "admin"]); $adminRole->save(); $userRole = new \App\Role(["title" => "user"]); $userRole->save(); $rescueRole = new \App\Role(["title" => "rescue"]); $rescueRole->save(); }
/** * Run the migrations. * * @return void */ public function up() { Schema::create('roles', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->text('description'); $table->text('tasks'); $table->string('reward'); $table->timestamps(); $table->softDeletes(); }); $roles = [['name' => 'Vanguard', 'description' => 'The Vanguard is the public leader of the team. When it comes to keeping morale up and team spirit high, this is your person.', 'tasks' => "[1] Organize and complete all team devotions. |[2] Promote team spirit and maintain peace among recruits.", 'reward' => "One hot pizza"], ['name' => 'Gamemaster', 'description' => 'The Gamemaster will lead the recruits into battle. This position requires one who can be decisive and commit to those decisions made.', 'tasks' => "[1] Lead the team during the challenges. |[2] Coordinate free time challenge participation.", 'reward' => 'Thirty minute gaming session'], ['name' => 'Culinarian', 'description' => 'Training the body and the mind requires fuel. The Culinarian will make sure that all recruits are well fed and ready to give their best.', 'tasks' => "[1] Coordinate food rations for team recruits. |[2] Acquire food from other teams by trading or purchase.", 'reward' => "Two major snacks"], ['name' => 'Technologist', 'description' => "During the course of the training, the Technologist will become well acquainted with the team's terminal, and will handle communication and puzzle-solving.", 'tasks' => "[1] Complete the Digital Quest. |[2] Coordinate the communication between teams and players.", 'reward' => 'One major snack'], ['name' => 'Engineer', 'description' => "The Engineer's skillset is the optimal blend of creativity and problem-solving. This recruit will be instrumental in gaining crucial points for their team.", 'tasks' => "[1] Using supplied materials, construct team's Space Car. |[2] Acquire supplies from another team by trading or purchase.", 'reward' => 'Additional tools/materials']]; foreach ($roles as $role) { $newRole = new \App\Role(); $newRole->name = $role['name']; $newRole->description = $role['description']; $newRole->tasks = $role['tasks']; $newRole->reward = $role['reward']; $newRole->save(); } }
public function setupFounderAndBaseRolesPermission() { $founder = new App\Role(); $founder->name = 'founder'; $founder->display_name = 'Project founder'; $founder->description = 'User is the founder of a given project'; $founder->save(); $admin = new App\Role(); $admin->name = 'admin'; $admin->display_name = 'User Administrator'; $admin->description = 'User is allowed to manage and edit other users'; $admin->save(); $user = new App\User(); $user->username = '******'; $user->email = '*****@*****.**'; $user->password = bcrypt('admin'); $user->is_admin = '1'; $user->save(); if (!$user->save()) { Log::info('Unable to create user ' . $user->username, (array) $user->errors()); } else { Log::info('Create user ' . $user->username . '<' . $user->email . '>'); } $user->attachRole($founder); $createPost = new App\Permission(); $createPost->name = 'manage_contents'; $createPost->display_name = 'Manage contents'; $createPost->description = 'Manage site all contents and post'; $createPost->save(); $editUser = new App\Permission(); $editUser->name = "edit_users"; $editUser->display_name = "Edit user"; $editUser->description = "edit user info"; $editUser->save(); $founder->attachPermission($createPost, $editUser); $admin->attachPermission($createPost); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create(); // create role $member = new App\Role(); $member->name = 'member'; $member->display_name = 'Member'; // optional $member->save(); $admin = new App\Role(); $admin->name = 'admin'; $admin->display_name = 'Administrator'; // optional $admin->save(); // create permission $memberPlaylist = new App\Permission(); $memberPlaylist->name = 'member-playlist'; $memberPlaylist->display_name = 'Manage Playlist by Member (self)'; $memberPlaylist->save(); $adminPlaylist = new App\Permission(); $adminPlaylist->name = 'admin-playlist'; $adminPlaylist->display_name = 'Manage Playlist by Admin'; $adminPlaylist->save(); // Assign permisson to role $member->attachPermissions([$memberPlaylist]); $admin->attachPermissions([$adminPlaylist]); // create admin $user = App\User::create(['name' => 'administrator', 'email' => '*****@*****.**', 'password' => bcrypt('password')]); // role attach alias $user->attachRole($admin); // create editor foreach (range(1, 3) as $i) { $user = App\User::create(['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt('password')]); // role attach alias $user->attachRole($member); } }
/** * Run the database seeds. * * @return void */ public function run() { // roles $admin = new \App\Role(); $admin->name = 'admin'; $admin->display_name = 'User Administrator'; $admin->description = 'User is allowed to manage and edit other users'; $admin->save(); $librarian = new \App\Role(); $librarian->name = 'librarian'; $librarian->display_name = 'User Librarian'; $librarian->description = 'User is allowed to manage the library'; $librarian->save(); $employee = new \App\Role(); $employee->name = 'employee'; $employee->display_name = 'User Employee'; $employee->description = 'User is allowed to rent, to reserve and to return the library copies'; $employee->save(); $teacher = new \App\Role(); $teacher->name = 'teacher'; $teacher->display_name = 'User Teacher'; $teacher->description = 'User is allowed to rent, to reserve and to return the library copies'; $teacher->save(); $student = new \App\Role(); $student->name = 'student'; $student->display_name = 'User Student'; $student->description = 'User is allowed to rent, to reserve and to return the library copies'; $student->save(); // permissions $toLoan = new \App\Permission(); $toLoan->name = 'to-loan'; $toLoan->display_name = 'To Loan'; $toLoan->description = 'To loan copies of works for students, teacher and employees'; $toLoan->save(); $librarian->attachPermission($toLoan); $toReserve = new \App\Permission(); $toReserve->name = 'to-reserve'; $toReserve->display_name = 'To Reserve'; $toReserve->description = 'To reserve copies of works for students, teacher and employees'; $toReserve->save(); $librarian->attachPermission($toReserve); $toReturn = new \App\Permission(); $toReturn->name = 'to-return'; $toReturn->display_name = 'To Return'; $toReturn->description = 'To return copies of works for students, teacher and employees'; $toReturn->save(); $librarian->attachPermission($toReturn); $toRenew = new \App\Permission(); $toRenew->name = 'to-renew'; $toRenew->display_name = 'To Renew'; $toRenew->description = 'To renew copies of works for students, teacher and employees'; $toRenew->save(); $librarian->attachPermission($toRenew); $addLibrarian = new \App\Permission(); $addLibrarian->name = 'add-librarian'; $addLibrarian->display_name = 'Add Librarian'; $addLibrarian->description = 'Can add librarian user'; $addLibrarian->save(); $admin->attachPermission($addLibrarian); $addEmployee = new \App\Permission(); $addEmployee->name = 'add-employee'; $addEmployee->display_name = 'Add Employee'; $addEmployee->description = 'Can add employee user'; $addEmployee->save(); $admin->attachPermission($addEmployee); $AddTeacher = new \App\Permission(); $AddTeacher->name = 'add-teacher'; $AddTeacher->display_name = 'Add Teacher'; $AddTeacher->description = 'Can add teacher user'; $AddTeacher->save(); $admin->attachPermission($AddTeacher); $addStudent = new \App\Permission(); $addStudent->name = 'add-student'; $addStudent->display_name = 'Add Student'; $addStudent->description = 'Can add student user'; $addStudent->save(); $admin->attachPermission($addStudent); $librarian->attachPermission($addStudent); $editLibrarian = new \App\Permission(); $editLibrarian->name = 'edit-librarian'; $editLibrarian->display_name = 'Edit Librarian'; $editLibrarian->description = 'Can edit librarian user'; $editLibrarian->save(); $admin->attachPermission($editLibrarian); $editEmployee = new \App\Permission(); $editEmployee->name = 'edit-employee'; $editEmployee->display_name = 'Edit Employee'; $editEmployee->description = 'Can edit employee user'; $editEmployee->save(); $admin->attachPermission($editEmployee); $editTeacher = new \App\Permission(); $editTeacher->name = 'edit-teacher'; $editTeacher->display_name = 'Edit Teacher'; $editTeacher->description = 'Can edit teacher user'; $editTeacher->save(); $admin->attachPermission($editTeacher); $editStudent = new \App\Permission(); $editStudent->name = 'edit-student'; $editStudent->display_name = 'Edit Student'; $editStudent->description = 'Can edit student user'; $editStudent->save(); $admin->attachPermission($editStudent); $librarian->attachPermission($editStudent); $editProfile = new \App\Permission(); $editProfile->name = 'edit-profile'; $editProfile->display_name = 'Edit Profile'; $editProfile->description = 'Can edit your user profile'; $editProfile->save(); $admin->attachPermission($editProfile); $librarian->attachPermission($editProfile); $employee->attachPermission($editProfile); $teacher->attachPermission($editProfile); $student->attachPermission($editProfile); $maxThreeCopies = new \App\Permission(); $maxThreeCopies->name = 'max-three-copies'; $maxThreeCopies->display_name = 'Max Three Copies'; $maxThreeCopies->description = 'Can catch loaned a maximum of three copies'; $maxThreeCopies->save(); $employee->attachPermission($maxThreeCopies); $student->attachPermission($maxThreeCopies); $maxFiveCopies = new \App\Permission(); $maxFiveCopies->name = 'max-five-copies'; $maxFiveCopies->display_name = 'Max Copies Five'; $maxFiveCopies->description = 'Can catch loaned a maximum of five copies'; $maxFiveCopies->save(); $teacher->attachPermission($maxFiveCopies); $maxTenDays = new \App\Permission(); $maxTenDays->name = 'max-ten-days'; $maxTenDays->display_name = 'Max Ten Days'; $maxTenDays->description = 'Can catch loaned by a maximum ten days'; $maxTenDays->save(); $employee->attachPermission($maxTenDays); $student->attachPermission($maxTenDays); $maxFifteenDays = new \App\Permission(); $maxFifteenDays->name = 'max-fifteen-days'; $maxFifteenDays->display_name = 'Max Fifteen Days'; $maxFifteenDays->description = 'Can catch loaned by a maximum fifteen days'; $maxFifteenDays->save(); $teacher->attachPermission($maxFifteenDays); $requestRenewal = new \App\Permission(); $requestRenewal->name = 'request-renewal'; $requestRenewal->display_name = 'Request Renewal'; $requestRenewal->description = 'Can request renewal of copies of works'; $requestRenewal->save(); $employee->attachPermission($requestRenewal); $teacher->attachPermission($requestRenewal); $student->attachPermission($requestRenewal); $requestReserve = new \App\Permission(); $requestReserve->name = 'request-reserve'; $requestReserve->display_name = 'Request Reserve'; $requestReserve->description = 'Can request reserve of works'; $requestReserve->save(); $employee->attachPermission($requestReserve); $teacher->attachPermission($requestReserve); $student->attachPermission($requestReserve); }
| Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', function () { return view('welcome'); }); Route::get('/entrust', function () { $owner = new App\Role(); $owner->name = 'owner'; $owner->display_name = 'Project Owner'; // optional $owner->description = 'User is the owner of a given project'; // optional $owner->save(); $admin = new App\Role(); $admin->name = 'admin'; $admin->display_name = 'User Administrator'; // optional $admin->description = 'User is allowed to manage and edit other users'; // optional $admin->save(); echo 1; $user = new \App\User(); $user->name = "John Nguyen"; $user->email = "*****@*****.**"; $user->password = bcrypt('123456'); $user->save(); $user->attachRole($admin); });