• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP models\Role类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中app\models\Role的典型用法代码示例。如果您正苦于以下问题:PHP Role类的具体用法?PHP Role怎么用?PHP Role使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Role类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: run

 public function run()
 {
     $adminEmail = Config::get('madison.seeder.admin_email');
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     $independent_sponsor = new Role();
     $independent_sponsor->name = 'Independent Sponsor';
     $independent_sponsor->save();
     $permIds = array();
     foreach ($this->adminPermissions as $permClass => $data) {
         $perm = new Permission();
         foreach ($data as $key => $val) {
             $perm->{$key} = $val;
         }
         $perm->save();
         $permIds[] = $perm->id;
     }
     $admin->perms()->sync($permIds);
     $user = User::where('email', '=', $adminEmail)->first();
     $user->attachRole($admin);
     $createDocPerm = new Permission();
     $createDocPerm->name = "independent_sponsor_create_doc";
     $createDocPerm->display_name = "Independent Sponsoring";
     $createDocPerm->save();
     $independent_sponsor->perms()->sync(array($createDocPerm->id));
 }
开发者ID:DCgov,项目名称:dc-madison,代码行数:27,代码来源:RbacSeeder.php


示例2: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $adminRole = new Role();
     $adminRole->name = 'admin';
     $adminRole->display_name = 'Admin';
     $adminRole->description = 'Admin for backend';
     $adminRole->is_admin = 1;
     $adminRole->save();
     $userRole = new Role();
     $userRole->name = 'user';
     $userRole->display_name = 'User';
     $userRole->description = 'user for backend';
     $userRole->is_admin = 0;
     $userRole->save();
     $admin = User::where('email', '[email protected]')->first();
     $assRoleAdmin = new AssignedRole();
     $assRoleAdmin->user_id = $admin->id;
     $assRoleAdmin->role_id = $adminRole->id;
     $assRoleAdmin->save();
     $user = User::where('email', '[email protected]')->first();
     $assRoleUser = new AssignedRole();
     $assRoleUser->user_id = $user->id;
     $assRoleUser->role_id = $userRole->id;
     $assRoleAdmin->save();
 }
开发者ID:viethung09,项目名称:kidblog,代码行数:30,代码来源:RolesTableSeeder.php


示例3: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $role = new Role();
     $role->name = 'Admin';
     $role->slug = str_slug('admin');
     $role->save();
 }
开发者ID:baconfy,项目名称:skeleton,代码行数:12,代码来源:RolesTableSeeder.php


示例4: destroy

 /**
  * Removes the specified user from the specified role.
  *
  * @param int|string $roleId
  * @param int|string $userId
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($roleId, $userId)
 {
     $this->authorize('admin.roles.users.destroy');
     $role = $this->role->findOrFail($roleId);
     $user = $role->users()->findOrFail($userId);
     // Retrieve the administrators name.
     $adminName = Role::getAdministratorName();
     // Retrieve all administrators.
     $administrators = $this->user->whereHas('roles', function ($query) use($adminName) {
         $query->whereName($adminName);
     })->get();
     $admin = Role::whereName($adminName)->first();
     // We need to verify that if the user is trying to remove all roles on themselves,
     // and they are the only administrator, that we throw an exception notifying them
     // that they can't do that. Though we want to allow the user to remove the
     // administrator role if more than one administrator exists.
     if ($user->hasRole($admin) && $user->id === auth()->user()->id && count($administrators) === 1) {
         flash()->setTimer(null)->error('Error!', "Unable to remove the administrator role from this user. You're the only administrator.");
         return redirect()->route('admin.roles.show', [$roleId]);
     }
     if ($role->users()->detach($user)) {
         flash()->success('Success!', 'Successfully removed user.');
         return redirect()->route('admin.roles.show', [$roleId]);
     }
     flash()->error('Error!', 'There was an issue removing this user. Please try again.');
     return redirect()->route('admin.roles.show', [$roleId]);
 }
开发者ID:stevebauman,项目名称:ithub,代码行数:35,代码来源:RoleUserController.php


示例5: run

 public function run()
 {
     DB::table('roles')->truncate();
     DB::table('role_user')->truncate();
     DB::table('permissions')->truncate();
     DB::table('permission_role')->truncate();
     $admin_role = new Role();
     $admin_role->name = 'admin';
     $admin_role->display_name = 'Administrator';
     $admin_role->description = 'manages everything';
     $admin_role->save();
     $reviewer_role = new Role();
     $reviewer_role->name = 'reviewer';
     $reviewer_role->display_name = 'Reviewer';
     $reviewer_role->description = 'reviews inserted data';
     $reviewer_role->save();
     $inserter_role = new Role();
     $inserter_role->name = 'inserter';
     $inserter_role->display_name = 'Inserter';
     $inserter_role->description = 'inserts data about billboards';
     $inserter_role->save();
     $admin = User::find(1);
     $reviewer = User::find(2);
     $inserters = User::whereNotIn('id', [$admin->id, $reviewer->id])->get();
     $admin->attachRole($admin_role);
     $reviewer->attachRole($reviewer_role);
     foreach ($inserters as $user) {
         $user->attachRole($inserter_role);
     }
 }
开发者ID:sagaciresearch,项目名称:adtracking,代码行数:30,代码来源:RoleTableSeeder.php


示例6: setupFoundorAndBaseRolsPermission

 public function setupFoundorAndBaseRolsPermission()
 {
     // Create Roles
     $founder = new Role();
     $founder->name = 'Founder';
     $founder->save();
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     // Create User
     $user = new User();
     $user->username = 'admin';
     $user->display_name = 'Admin';
     $user->email = '[email protected]';
     $user->password = 'admin';
     if (!$user->save()) {
         Log::info('Unable to create user ' . $user->username, (array) $user->errors());
     } else {
         Log::info('Created user "' . $user->username . '" <' . $user->email . '>');
     }
     // Attach Roles to user
     $user->roles()->attach($founder->id);
     // Create Permissions
     $manageContent = new Permission();
     $manageContent->name = 'manage_contents';
     $manageContent->display_name = 'Manage Content';
     $manageContent->save();
     $manageUsers = new Permission();
     $manageUsers->name = 'manage_users';
     $manageUsers->display_name = 'Manage Users';
     $manageUsers->save();
     // Assign Permission to Role
     $founder->perms()->sync([$manageContent->id, $manageUsers->id]);
     $admin->perms()->sync([$manageContent->id]);
 }
开发者ID:axex,项目名称:kratos,代码行数:35,代码来源:2016_01_25_135943_entrust_setup_tables.php


示例7: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $user_1 = new User();
     $user_1->name = 'tech';
     $user_1->email = '[email protected]';
     $user_1->password = \Hash::make('tech1234');
     $user_1->phone = '082214250262';
     $user_1->jabatan = 'Technical Administrator';
     $user_1->save();
     $user_2 = new User();
     $user_2->name = 'admin';
     $user_2->email = '[email protected]';
     $user_2->password = \Hash::make('admin1234');
     $user_2->phone = '082214250262';
     $user_2->jabatan = 'Management Administrator';
     $user_2->save();
     $role_1 = new Role();
     $role_1->name = 'tech';
     $role_1->display_name = 'tech';
     $role_1->description = 'Technical Administration';
     $role_1->save();
     $role_2 = new Role();
     $role_2->name = 'admin';
     $role_2->display_name = 'admin';
     $role_2->description = 'Management Administration';
     $role_2->save();
     $user_1->attachRole($role_1);
     $user_2->attachRole($role_2);
 }
开发者ID:k1m0ch1,项目名称:egor,代码行数:34,代码来源:UsersSeeder.php


示例8: run

 public function run()
 {
     $roles = ['admin', 'user'];
     foreach ($roles as $role) {
         $instance = new Role(['role' => $role]);
         $instance->save();
     }
 }
开发者ID:koanreview,项目名称:Laravel5Starter,代码行数:8,代码来源:RolesSeeder.php


示例9: run

 public function run()
 {
     DB::table('roles')->delete();
     $adminRole = new Role();
     $adminRole->name = 'admin';
     $adminRole->save();
     $user = User::where('name', '=', 'admin')->first();
     $user->attachRole($adminRole);
 }
开发者ID:Zachary-Leung,项目名称:wine_platform,代码行数:9,代码来源:RolesTableSeeder.php


示例10: execute

 /**
  * @param array $data
  * @return bool
  */
 public function execute(array $data)
 {
     if (!$this->isValid($data)) {
         return false;
     }
     $role = new Role();
     $role->name = $data['name'];
     $role->slug = str_slug($data['name']);
     return $role->save();
 }
开发者ID:baconfy,项目名称:skeleton,代码行数:14,代码来源:CreateRole.php


示例11: completeRegistration

 public function completeRegistration($params = array())
 {
     $user = $this->api->user();
     $defaults = array('verification_code' => $verification_code = null, 'app_subdomain' => $app_subdomain = null, 'email_domains' => $email_domains = null, 'name' => $name = null);
     $this->api->validation_factory->extend('email_domains', function ($attribute, $value, $parameters) {
         $email_domains = $this->toArray($value);
         foreach ($email_domains as $domain) {
             if (!filter_var('fakeemail@' . $domain, FILTER_VALIDATE_EMAIL)) {
                 return false;
             }
         }
         return true;
     });
     $rules = array('verification_code' => array('required', 'exists:organizations,verification_code,registration_complete,0'), 'app_subdomain' => array('required', 'alpha_dash', 'unique:organizations'), 'email_domains' => array('sometimes', 'email_domains'));
     $messages = array('app_subdomain.alpha_dash' => 'Please enter a valid subdomain', 'app_subdomain.unique' => 'The requested subdomain is not available', 'email_domains.email_domains' => 'Please enter valid email domains');
     $params = $this->validateParams($defaults, $params, $rules, $messages);
     extract($params);
     /**
      * @var Organization
      */
     $organization = $this->query()->where('verification_code', $verification_code)->where('registration_complete', false)->first();
     $organization->app_subdomain = $app_subdomain;
     if (!empty($name)) {
         $organization->name = $name;
     }
     /**
      * It's possible that during the time when the above unique subdomain validation
      * is run and the time the organization is saved, that someone else claimed the subdomain.
      * In that case, the save() query will fail, so we wrap it in a try/catch.
      */
     try {
         $organization->save();
         $email_domains = $this->toArray($email_domains);
         if (!empty($email_domains)) {
             $saved_email_domains = array();
             foreach ($email_domains as $email_domain) {
                 $saved_email_domains[] = new EmailDomain(array('domain' => trim($email_domain)));
             }
             $organization->emailDomains()->saveMany($saved_email_domains);
         }
         $admin = new Role();
         $admin->name = $organization->roleAdminName();
         $admin->display_name = $organization->roleAdminDisplayName();
         $admin->save();
         $user->attachRole($admin);
         $organization->registration_complete = true;
         $organization->save();
         $this->entity = $organization;
         $this->api->event->fire(new OrganizationRegistrationCompleted($organization));
         return $this->entity();
     } catch (QueryException $e) {
         throw new BadRequestException('The requested subdomain is not available');
     }
 }
开发者ID:shaunpersad,项目名称:reflect-api,代码行数:54,代码来源:OrganizationsResource.php


示例12: store

 /**
  * Adds the specified permission onto the requested roles.
  *
  * @param PermissionRoleRequest $request
  * @param int|string            $permissionId
  *
  * @return array|false
  */
 public function store(PermissionRoleRequest $request, $permissionId)
 {
     $this->authorize('admin.roles.permissions.store');
     $permission = $this->permission->findOrFail($permissionId);
     $roles = $request->input('roles', []);
     if (count($roles) > 0) {
         $roles = $this->role->findMany($roles);
         return $permission->roles()->saveMany($roles);
     }
     return false;
 }
开发者ID:stevebauman,项目名称:administration,代码行数:19,代码来源:PermissionRoleProcessor.php


示例13: addRole

 public static function addRole($name, $label = null, $description = null)
 {
     $role = Role::query()->where('name', $name)->first();
     if (!$role) {
         $role = new Role(['name' => $name]);
     }
     $role->label = $label;
     $role->description = $description;
     $role->save();
     return $role;
 }
开发者ID:liuzhaowei55,项目名称:Moorper,代码行数:11,代码来源:Role.php


示例14: run

 public function run()
 {
     $items = [["Assistant", "C'est un assistant. Il fait des trucs d'assistant."], ["Soigneur", "Un soigneur guéri un athlète à l'aide de sa magie blanche."], ["Accompagnateur", "Un accompagnateur accompagne un athlète pour qu'il ne soit pas seul."]];
     DB::table('roles')->delete();
     foreach ($items as $item) {
         $role = new Role();
         $role->nom = $item[0];
         $role->description = $item[1];
         $role->save();
     }
 }
开发者ID:BenoitDesrosiers,项目名称:GES2015,代码行数:11,代码来源:RolesSeeder.php


示例15: store

 /**
  * Adds the specified permission to the requested roles.
  *
  * @param PermissionRoleRequest $request
  * @param int|string            $permissionId
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store(PermissionRoleRequest $request, $permissionId)
 {
     $this->authorize('admin.roles.permissions.store');
     $permission = $this->permission->findOrFail($permissionId);
     $roles = $request->input('roles', []);
     if (count($roles) > 0) {
         $roles = $this->role->findMany($roles);
         $permission->roles()->saveMany($roles);
         flash()->success('Success!', 'Successfully added roles.');
         return redirect()->route('admin.permissions.show', [$permissionId]);
     }
     flash()->error('Error!', "You didn't select any roles!");
     return redirect()->route('admin.permissions.show', [$permissionId]);
 }
开发者ID:stevebauman,项目名称:ithub,代码行数:22,代码来源:PermissionRoleController.php


示例16: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('roles')->delete();
     Role::create(['name' => 'user']);
     Role::create(['name' => 'editor']);
     Role::create(['name' => 'administrator']);
 }
开发者ID:vladochek,项目名称:laravel-auth,代码行数:12,代码来源:SeedRoles.php


示例17: run

 public function run()
 {
     DB::statement("SET foreign_key_checks = 0");
     Role::truncate();
     Role::create(['name' => 'user']);
     Role::create(['name' => 'administrator']);
 }
开发者ID:suchayj,项目名称:easymanage,代码行数:7,代码来源:RoleSeeder.php


示例18: edit

 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit(User $User)
 {
     $this->data['Roles'] = Role::all();
     $this->data['Groups'] = Group::all();
     $this->data['User'] = $User;
     return view('admin.users.edit', $this->data);
 }
开发者ID:DJZT,项目名称:tezter,代码行数:13,代码来源:UsersController.php


示例19: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $permissions = $this->getAllActions();
     $actions = $this->getRouteData();
     $roles = Role::all();
     // Add new actions
     foreach ($actions as $action => $uri) {
         if (!array_key_exists($action, $permissions)) {
             $newAction = new Action(['action' => $action, 'uri' => $uri]);
             $newAction->save();
             $this->savePermissions($roles, $newAction);
             $this->info("Added " . $action . "\n");
         } else {
             unset($permissions[$action]);
         }
     }
     // Remove non existing actions
     foreach ($permissions as $action => $uri) {
         Action::where(['action' => $action, 'uri' => $uri])->first()->destroy();
         $this->comment("Removed " . $action . "\n");
     }
     $cache = $this->getCacheInstance(['permissions']);
     $cache->flush();
     $this->info("Done. \n");
 }
开发者ID:Denniskevin,项目名称:Laravel5Starter,代码行数:30,代码来源:AclUpdate.php


示例20: store

 /**
  * Store a newly created resource in storage.
  *
  * @param AdduserRequest $request
  * @return \Illuminate\Http\Response
  */
 public function store(AdduserRequest $request)
 {
     //        $input = $request->all();                               // get all data
     //        $input['confirmed'] = 1;                                // set confirmed to 1
     //        $input['password'] = Hash::make($input['password']);    // hash password
     //
     //        $user       =   User::create($input);                   // save above details
     $user = User::create(['first_name' => $request->first_name, 'last_name' => $request->last_name, 'email' => $request->email, 'confirmed' => 1, 'password' => Hash::make($request->password)]);
     //        $profile    =   $user->profile()->save(new Profile);    // also create new profile
     //        $profile->apartment_id  =   Auth::user()->profile->defaultApartment; // get current defaultApartment
     //        $profile->save();                                       // save details on profile
     $profile = Profile::create(['user_id' => $user->id, 'apartment_id' => Auth::user()->profile->defaultApartment]);
     dd(Auth::user()->profile->defaultApartment);
     $role = Role::whereName('user')->first();
     $user->assignRole($role);
     //Assign Role
     $block_no = $request->blockno;
     // get block_no from profileform
     $floor_no = $request->floorno;
     // get floor_no from profileform
     $profile->apartments()->attach($profile->defaultApartment, ['approved' => '1', 'block_no' => $block_no, 'floor_no' => $floor_no]);
     // attach this profile with default apartment, with approved = 1, and block_no, floor_no according to profileform in apartment_profile pivot table.
     Crm_account::create(['account' => $user->first_name . $user->last_name, 'fname' => $user->first_name, 'lname' => $user->last_name, 'company' => 'Company Name', 'email' => $user->email, 'address' => 'Current Address', 'city' => 'Nagpur', 'state' => 'Maharashtra', 'zip' => '440012', 'country' => 'India']);
     return redirect()->back()->withMessage('User has been Added')->withStatus('success');
 }
开发者ID:suchayj,项目名称:easymanage,代码行数:31,代码来源:AdduserController.php



注:本文中的app\models\Role类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP models\Setting类代码示例发布时间:2022-05-23
下一篇:
PHP models\Region类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap