当前位置: 首页>>代码示例>>PHP>>正文


PHP User::attachRole方法代码示例

本文整理汇总了PHP中app\User::attachRole方法的典型用法代码示例。如果您正苦于以下问题:PHP User::attachRole方法的具体用法?PHP User::attachRole怎么用?PHP User::attachRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\User的用法示例。


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

示例1: createTestStub

 /**
  * Stubbing test data.
  *
  * @param array $overrides
  */
 protected function createTestStub($overrides = [])
 {
     $this->user = empty($overrides) ? factory(User::class)->create() : factory(User::class)->create($overrides);
     $this->user->attachRole(Role::find(2));
     $this->article = factory(Article::class)->create(['title' => 'title', 'author_id' => $this->user->id, 'content' => 'description']);
     $this->article->comments()->save(factory(Comment::class)->make(['author_id' => $this->user->id]));
     $this->article->tags()->attach(1);
     $this->article->attachments()->save(factory(Attachment::class)->make());
 }
开发者ID:hongpyo,项目名称:l5essential,代码行数:14,代码来源:ApiTest.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(CreateUserRequest $request)
 {
     $data = $request->all();
     $user = new User();
     $user->fill($data);
     $user->full_name = $data['first_name'] . " " . $data['last_name'];
     $user->save();
     if ($data['type'] == 1) {
         $user->attachRole(1);
     } elseif ($data['type'] == 2) {
         $user->attachRole(2);
     }
     $message = "Usuario Creado correctamente";
     Session::flash('success', $message);
     return redirect()->route('admin.users.index');
 }
开发者ID:JJDJ,项目名称:asoproam,代码行数:22,代码来源:UsersController.php

示例3: adminSubmit

 public function adminSubmit(User $user, Request $request)
 {
     $h = implode(',', Role::latest()->lists('id')->toArray());
     $this->validate($request, ['role' => "required|in:{$h}"]);
     $input = $request->except('_token');
     $role = $input['role'];
     $roleObject = Role::find($role);
     if (!$user->is($role)) {
         if ($roleObject->slug == 'user' || $roleObject->slug == 'legal') {
             if (!$user->is('user') && !$user->is('legal')) {
                 $user->attachRole($role);
             }
         } else {
             $user->attachRole($role);
         }
     }
     return redirect()->back();
 }
开发者ID:emadmrz,项目名称:Hawk,代码行数:18,代码来源:RoleController.php

示例4: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  DirectorRequest $request
  * @return Response
  */
 public function store(DirectorRequest $request)
 {
     $role = Role::getByName('administrador');
     $director = new User();
     $director->fill($request->all());
     $tipo = Tipo::getByName('Director');
     $director->tipo_id = $tipo->id;
     $director->password = Hash::make($request->input('password'));
     $director->save();
     $director->attachRole($role->id);
     return redirect()->route('admin.director.index');
 }
开发者ID:ericray,项目名称:test,代码行数:18,代码来源:DirectorController.php

示例5: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $name = $this->ask("Please enter your name");
     $email = $this->ask("Please enter your email");
     $password = $this->secret("Please enter your password");
     $role_choice = $this->choice("Choose role you want have,seperated by comma", ["su", "user", "admin"], true, null, false);
     if ($this->confirm("Do you wish to generate? [y|N]")) {
         $user = new User();
         $user->name = $name;
         $user->email = $email;
         $user->password = bcrypt($password);
         $user->save();
         $role = Role::where('name', $role_choice)->first();
         $user->attachRole($role);
     }
     $this->info("success!");
 }
开发者ID:xuboso,项目名称:egop,代码行数:22,代码来源:GenerateUser.php

示例6: createRoleAdmin

 public function createRoleAdmin()
 {
     $admin = new Role();
     $admin->name = 'admin';
     $admin->display_name = 'User Administrator';
     // optional
     //$admin->description  = 'User is allowed to manage and edit other users'; // optional
     $admin->save();
     $user = new User();
     $user->name = 'superadmin';
     $user->email = 'superadmin@azorro.com';
     $user->password = Hash::make('123456789');
     $user->save();
     // role attach alias
     $user->attachRole($admin);
     // parameter can be an Role object, array, or id
     return "Admin created. Name: superadmin";
     // or eloquent's original technique
     // $user->roles()->attach($admin->id); // id only
 }
开发者ID:ShehabSunny,项目名称:ProductZap,代码行数:20,代码来源:RolesController.php

示例7: create_user

 /**
  * Function create user
  * @author  Tran Van Moi <[moitran92@gmail.com]>
  * @since  2015/05/13
  * @param  array $user_info
  * @param  string $role_name
  * @return object
  */
 public static function create_user($user_info, $role_name)
 {
     $user = new User();
     $user->name = $user_info['name'];
     $user->uid = empty($user_info['id']) ? 'res_local' : $user_info['id'];
     $user->email = $user_info['email'];
     $user->image = $user_info['image'];
     $user->password = Hash::make($user_info['password']);
     if (isset($user_info['birthday'])) {
         $user->birthday = $user_info['birthday'];
     }
     if (isset($user_info['address'])) {
         $user->address = $user_info['address'];
     }
     $user->save();
     // attack role to user
     $role = Role::whereName($role_name)->first();
     $user->attachRole($role);
     return $user;
 }
开发者ID:ambarsetyawan,项目名称:laravel-1,代码行数:28,代码来源:User.php

示例8: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //Create admin role
     $adminRoleName = 'admin';
     $adminRole = Role::where('name', $adminRoleName)->first();
     if (!$adminRole) {
         $adminRole = new Role();
         $adminRole->name = $adminRoleName;
         $adminRole->save();
     }
     //Create admin user
     $adminUserEmail = 'admin@admin.com';
     $adminUserPassword = 'admin';
     $adminUser = User::where('email', $adminUserEmail)->first();
     if (!$adminUser) {
         $adminUser = new User();
         $adminUser->email = $adminUserEmail;
         $adminUser->password = Hash::make($adminUserPassword);
         $adminUser->save();
     }
     //Attach Role to User
     $adminUser->detachRoles($adminUser->roles);
     $adminUser->attachRole($adminRole);
 }
开发者ID:kilrizzy,项目名称:laraticket,代码行数:29,代码来源:AdminTableSeeder.php

示例9: onUserActivated

 /**
  * Handle user's email confirmation event
  *
  * @param User $user
  *
  * @return mixed
  */
 public function onUserActivated(User $user)
 {
     if ($user->activated != 1) {
         // Update 'activated' attributes
         $now = new \DateTime();
         $user->activated_at = $now->format('Y-m-d H:i:s');
         $user->activated = 1;
         $user->activation_code = null;
         $user->save();
         // Promote user role to 'member'
         $user->attachRole(Role::whereSlug('member')->first());
         // Send welcome email
         $email = $user->email;
         $subject = trans('email-subject.activated');
         $view = 'emails.activated';
         $link = route('session.create');
         $data = compact('subject', 'link');
         $cc = [];
         $bcc = [];
         $this->mailer->send($email, $subject, $view, $data, $cc, $bcc);
     }
     return true;
 }
开发者ID:valdinei,项目名称:rest,代码行数:30,代码来源:AuthEventListener.php

示例10: PostCrearAlumno

 public function PostCrearAlumno()
 {
     $alumno = new User();
     $alumno->name = Input::get("name");
     $alumno->last_name = Input::get("last_name");
     $alumno->email = Input::get("email");
     $alumno->estado = Input::get("estado");
     $alumno->imagen_perfil = 'default' . rand(1, 12) . '.jpg';
     $alumno->setPasswordAttribute('kayracrossfit');
     $alumno->save();
     $alumnoRole = Role::find(1);
     $alumno->attachRole($alumnoRole);
     if ($alumno->estado == 'activo') {
         $alumno->cuenta_activa = true;
         $alumno->save();
         $data = array('fullname' => $alumno->name . " " . $alumno->last_name, 'email' => $alumno->email);
         $email = $alumno->email;
         \Mail::send('emails.bienvenidos', $data, function ($message) use($email) {
             $message->from('hola@kayracrossfit.com', 'BoxMagic');
             $message->to($email)->subject('Bienvenido a Kayra!!!');
         });
     }
     return redirect('alumnos/lista');
 }
开发者ID:davila7,项目名称:kayra,代码行数:24,代码来源:AlumnosController.php

示例11: create

 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     //    $arquivo    = $data['foto'];
     //    $extension  = $arquivo->getClientOriginalExtension();
     //    $image_name = 'user';
     //    $path       = $arquivo->getRealPath();
     //
     //    Storage::put('users/'.$image_name.$data['email'].'.'.$extension,file_get_contents($path));
     //  //  $user->foto = '/image/users/'.$image_name;
     //        $user = User::create([
     //            'name' => $data['name'],
     //            'email' => $data['email'],
     //            'password' => bcrypt($data['password']),
     //            'telefone'=>$data['telefone'],
     //            'endereco'=>$data['endereco'],
     //            'foto' =>'image/users/'.$image_name,
     //        ]);
     $user = new User();
     $user->name = $data['name'];
     $user->email = $data['email'];
     $user->password = bcrypt($data['password']);
     $user->telefone = $data['telefone'];
     $user->endereco = $data['endereco'];
     $arquivo = $data['foto'];
     $extension = $arquivo->getClientOriginalExtension();
     $image_name = 'user' . $user->id;
     $path = $arquivo->getRealPath();
     Storage::put('users/' . $image_name . '.' . $extension, file_get_contents($path));
     $user->foto = '/image/users/' . $image_name;
     $user->save();
     $role = Role::where('name', '=', 'user')->first();
     $user->attachRole($role);
     return $user;
 }
开发者ID:pedrohbraz,项目名称:rifasPando,代码行数:40,代码来源:AuthController.php

示例12: createUserStub

 /**
  * Create User.
  *
  * @param array $overrides
  * @return $this
  */
 protected function createUserStub($overrides = [])
 {
     $this->user = empty($overrides) ? factory(User::class)->create() : factory(User::class)->create($overrides);
     $this->user->attachRole(Role::find(2));
     return $this;
 }
开发者ID:linuxssm,项目名称:l5essential,代码行数:12,代码来源:ApiTest.php

示例13: postPermissions

 /**
  * @param Request $request
  * @param User $user
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function postPermissions(Request $request, User $user)
 {
     $role = Role::find($request->role);
     if ($request->role == 0) {
         $user->detachRoles();
     } else {
         $user->attachRole($role);
     }
     flash()->success(trans('members.success.permissions', ['user' => $user->username, 'role' => strtolower($role ? trans('members.roles.' . $role->name) : trans('members.roles.member'))]));
     return redirect('admin/members/manage');
 }
开发者ID:huludini,项目名称:aura-kingdom-web,代码行数:16,代码来源:MembersController.php

示例14: PostCrearRecepcion

 public function PostCrearRecepcion()
 {
     $recep = new User();
     $recep->name = Input::get("name");
     $recep->last_name = Input::get("last_name");
     $recep->email = Input::get("email");
     $recep->rut = Input::get("rut");
     $recep->imagen_perfil = 'default.jpg';
     $recep->setPasswordAttribute(Input::get("rut"));
     $recep->save();
     $recepRole = Role::find(4);
     $recep->attachRole($recepRole);
     return redirect('recepcion/lista');
 }
开发者ID:davila7,项目名称:kayra,代码行数:14,代码来源:AdministracionController.php

示例15: seedDataSource

 /**
  * Seed Data Source
  *
  * @author MS
  * @return void
  */
 protected function seedDataSource()
 {
     Model::unguard();
     foreach ($this->permissions as $permissionsToAdd) {
         $permissionObject = new Permission();
         $permissionObject->name = $permissionsToAdd[1];
         $permissionObject->display_name = $permissionsToAdd[0];
         $permissionObject->description = $permissionsToAdd[2];
         $permissionObject->save();
     }
     $roles = [];
     foreach ($this->roles as $rolesToAdd) {
         $roleObject = new Role();
         $roleObject->name = $rolesToAdd[1];
         $roleObject->display_name = $rolesToAdd[0];
         $roleObject->description = $rolesToAdd[2];
         $roleObject->save();
         $roles[] = $roleObject;
     }
     foreach ($this->rolesPermissions as $role => $permissionsToAdd) {
         foreach ($permissionsToAdd as $permission) {
             $role1 = Role::findOrFail($role + 1);
             $role1->permissions()->attach($permission);
         }
     }
     foreach ($this->users as $user) {
         $userObject = new User();
         $userObject->name = $user[0];
         $userObject->email = $user[1];
         $userObject->password = bcrypt($user[2]);
         $userObject->merchant_id = $user[3];
         $userObject->role_id = $user[4];
         $userObject->save();
         $userObject->attachRole($roles[$user[4] - 1]);
     }
     (new PermissionSeeder())->run();
     Model::reguard();
 }
开发者ID:paybreak,项目名称:basket,代码行数:44,代码来源:DBSeeder.php


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