本文整理汇总了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());
}
示例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');
}
示例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();
}
示例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');
}
示例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!");
}
示例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
}
示例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;
}
示例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);
}
示例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;
}
示例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');
}
示例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;
}
示例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;
}
示例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');
}
示例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');
}
示例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();
}