本文整理汇总了PHP中app\models\User::attachRole方法的典型用法代码示例。如果您正苦于以下问题:PHP User::attachRole方法的具体用法?PHP User::attachRole怎么用?PHP User::attachRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\User
的用法示例。
在下文中一共展示了User::attachRole方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$user_1 = new User();
$user_1->name = 'tech';
$user_1->email = 'tech@ordent.co';
$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 = 'admin@ordent.co';
$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);
}
示例2: postRegisterAjax
public function postRegisterAjax(Request $request)
{
// try {
$firstname = $request->input('firstname');
$lastname = $request->input('lastname');
$email = $request->input('email');
$username = $request->input('email');
$password = $request->input('password');
try {
$user = User::where('email', '=', $email)->first();
if ($user) {
return ['success' => '0', 'results' => '', 'messages' => 'The account already exists in weDonate.', 'redirect' => ''];
}
} catch (Exception $e) {
Log::error($e);
}
// TODO: create a globa function to create a user
$user = new User();
$user->uuid = Uuid::generate(4);
$user->registered_ip = $_SERVER['REMOTE_ADDR'];
$user->registered_provider = 'email';
$user->last_login_ip = null;
$user->last_login_datetime = date('Y-m-d H:i:s');
$user->email = $email;
$user->username = $email;
$user->password = Hash::make($password);
$user->referrer_code = Uuid::generate(1, '0123456');
$user->save();
$profile = new UserProfile();
$profile->user_id = $user->id;
$profile->firstname = $firstname;
$profile->lastname = $lastname;
if ($request->has('referrer')) {
$profile->referrer_id = User::where('referrer_code', '=', $request->has('referrer_code'))->first();
}
$profile->ranking = (int) User::all()->count();
$profile->save();
$role = Role::where('name', '=', 'donator')->first();
$user->attachRole($role);
if (Auth::attempt(['username' => $email, 'password' => $password])) {
Log::info('USer registered, id=' . $user->id);
return ['success' => '1', 'results' => '', 'messages' => 'Successfully connected.', 'redirect' => route('getDash')];
} else {
return ['success' => '0', 'results' => '', 'messages' => 'An errorred occurred.', 'redirect' => ''];
}
// } catch (Exception $e) {
return ['success' => '0', 'results' => '', 'messages' => 'An errorred occurred.', 'redirect' => ''];
// }
}
示例3: postStore
public function postStore()
{
$this->sanarInputProfesor();
$profesor = new Profesor();
$profesor->nombres = Request::input('nombres');
$profesor->apellidos = Request::input('apellidos');
$profesor->sexo = Request::input('sexo');
$profesor->tipo_doc = Request::input('tipo_doc');
$profesor->num_doc = Request::input('num_doc');
$profesor->ciudad_doc = Request::input('ciudad_doc');
$profesor->fecha_nac = Request::input('fecha_nac');
$profesor->ciudad_nac = Request::input('ciudad_nac');
$profesor->titulo = Request::input('titulo');
$profesor->estado_civil = Request::input('estado_civil');
$profesor->barrio = Request::input('barrio');
$profesor->direccion = Request::input('direccion');
$profesor->telefono = Request::input('telefono');
$profesor->celular = Request::input('celular');
$profesor->facebook = Request::input('facebook');
$profesor->email = Request::input('email');
$profesor->tipo_profesor = Request::input('tipo_profesor');
$profesor->save();
$this->sanarInputUser();
$this->checkOrChangeUsername($profesor->user_id);
$usuario = new User();
$usuario->username = Request::input('username');
$usuario->password = Hash::make(Request::input('password', '123456'));
$usuario->email = Request::input('email2');
$usuario->is_superuser = Request::input('is_superuser', false);
$usuario->is_active = Request::input('is_active', true);
$usuario->tipo = 'Profesor';
$usuario->save();
$profesor->user_id = $usuario->id;
$role = Role::where('name', '=', 'Profesor')->get();
$usuario->attachRole($role[0]);
$profesor->save();
$profesor->user = $usuario;
if (Request::input('grupo')['id']) {
$grupo_id = Request::input('grupo')['id'];
$matricula = new Matricula();
$matricula->alumno_id = $profesor->id;
$matricula->grupo_id = $grupo_id;
$matricula->matriculado = true;
$matricula->save();
$grupo = Grupo::find($matricula->grupo_id);
$profesor->grupo = $grupo;
}
return $profesor;
}
示例4: run
public function run()
{
$programme = Programme::where('id', '=', '420AA')->first();
$classeCN2 = Classe::where('code', '=', '420-CN2-DM')->first();
$classeDM1 = Classe::where('code', '=', '420-DM1-DM')->first();
$classeDM2 = Classe::where('code', '=', '420-DM2-DM')->first();
$roleadmin = Role::where('name', '=', 'admin')->first();
$roleprof = Role::where('name', '=', 'professeur')->first();
$roleetudiant = Role::where('name', '=', 'etudiant')->first();
DB::table('users_classes')->delete();
DB::table('users')->delete();
$user = new User();
$user->name = 'Admin';
$user->nom = 'systeme';
$user->prenom = 'admin';
$user->type = 'p';
$user->email = 'admin@chose.com';
$user->password = Hash::make('usager');
$user->save();
$user->attachRole($roleadmin);
$user = new User();
$user->name = 'prof1';
$user->nom = 'prof1 ';
$user->prenom = 'un';
$user->type = 'p';
$user->email = 'prof1@chose.com';
$user->password = Hash::make('usager');
$programme->users()->save($user);
$user->attachRole($roleprof);
$user->classes()->sync([$classeCN2->id, $classeDM1->id]);
$user = new User();
$user->name = 'prof2';
$user->nom = 'prof2 ';
$user->prenom = 'deux';
$user->type = 'p';
$user->email = 'prof2@chose.com';
$user->password = Hash::make('usager');
$programme->users()->save($user);
$user->attachRole($roleprof);
$user->classes()->sync([$classeCN2->id, $classeDM2->id]);
$user = new User();
$user->name = 'etudiant1';
$user->nom = 'etudiant';
$user->prenom = 'un';
$user->type = 'e';
$user->email = 'etudiant1@chose.com';
$user->password = Hash::make('usager');
$programme->users()->save($user);
$user->attachRole($roleetudiant);
$user->classes()->sync([$classeCN2->id, $classeDM1->id]);
$user = new User();
$user->name = 'etudiant2';
$user->nom = 'etudiant2';
$user->prenom = 'deux';
$user->type = 'e';
$user->email = 'etudiant2@chose.com';
$user->password = Hash::make('usager');
$programme->users()->save($user);
$role = Role::where('name', '=', 'etudiant')->first();
$user->attachRole($roleetudiant);
$user->classes()->sync([$classeCN2->id, $classeDM1->id, $classeDM2->id]);
}
示例5: postUserCreate
public function postUserCreate(Request $request)
{
//Start transaction
DB::beginTransaction();
try {
$firstname = $request->input('firstname');
$lastname = $request->input('lastname');
$email = $request->input('email');
$username = $request->input('email');
$password = $request->input('password');
try {
$user = User::where('email', '=', $email)->first();
if ($user) {
return ['success' => '0', 'results' => '', 'messages' => 'The account already exists in weDonate.', 'redirect' => ''];
}
} catch (Exception $e) {
}
// TODO: create a globa function to create a user
$user = new User();
$user->uuid = Uuid::generate(4);
$user->registered_ip = $_SERVER['REMOTE_ADDR'];
$user->registered_provider = 'email';
$user->last_login_ip = null;
$user->last_login_datetime = date('Y-m-d H:i:s');
$user->email = $email;
$user->username = $email;
$user->password = Hash::make($password);
$user->referrer_code = Uuid::generate(1, '0123456');
$user->save();
$profile = new UserProfile();
$profile->user_id = $user->id;
$profile->firstname = $firstname;
$profile->lastname = $lastname;
if ($request->has('referrer')) {
$profile->referrer_id = User::where('referrer_code', '=', $request->has('referrer_code'))->first();
}
$profile->ranking = (int) User::all()->count();
$profile->save();
$role = Role::where('id', '=', $request->input('role'))->first();
$user->attachRole($role);
Log::info('User created, id=' . $user->uuid);
//send email
$message = $this->sendEmail($email, $user->id);
// If we reach here, then
// data is valid and working.
// Commit the queries!
DB::commit();
return redirect(route('getUserCreate'))->withFlashMessage($message);
} catch (Exception $e) {
DB::rollback();
throw $e;
}
}
示例6: createAndAsignUser
public function createAndAsignUser($persona, $tipo)
{
$newU = new User();
$name = preg_replace('/\\s+/', '', $persona->nombres);
$nom = filter_var($name, FILTER_SANITIZE_EMAIL);
$user = User::where('username', '=', $nom)->first();
//mientras el user exista iteramos y aumentamos i
if ($user) {
$username = $user->username;
$i = 0;
while (sizeof(User::where('username', '=', $username)->first()) > 0) {
$i++;
$username = $user->username . $i;
}
$nom = $username;
}
$newU->username = $nom;
$newU->save();
if ($tipo == 'Profesor') {
$newU->attachRole(2);
}
if ($tipo == 'Alumno') {
$newU->attachRole(3);
}
if ($tipo == 'Acudiente') {
$newU->attachRole(4);
}
$persona->user_id = $newU->id;
$persona->save();
}
示例7: handleLdapUserWasAuthenticated
/**
* Attaches roles depending on the users active directory group.
*
* @param User $user
* @param AdldapUser $adldapUser
*/
protected function handleLdapUserWasAuthenticated(User $user, AdldapUser $adldapUser)
{
if ($adldapUser->inGroup('Help Desk')) {
$admin = Role::admin();
if ($admin instanceof Role) {
$user->attachRole($admin->getKey());
}
}
}
示例8: postStore
public function postStore()
{
$user = User::fromToken();
$alumno = [];
try {
$this->sanarInputAlumno();
$date = Carbon::createFromFormat('Y-m-d', Request::input('fecha_nac'));
$alumno = new Alumno();
$alumno->no_matricula = Request::input('no_matricula');
$alumno->nombres = Request::input('nombres');
$alumno->apellidos = Request::input('apellidos');
$alumno->sexo = Request::input('sexo');
#$alumno->user_id = Request::input('user_id');
$alumno->fecha_nac = $date->format('Y-m-d');
$alumno->ciudad_nac = Request::input('ciudad_nac');
$alumno->tipo_doc = Request::input('tipo_doc');
$alumno->documento = Request::input('documento');
$alumno->ciudad_doc = Request::input('ciudad_doc');
$alumno->tipo_sangre = Request::input('tipo_sangre')['sangre'];
$alumno->eps = Request::input('eps');
$alumno->telefono = Request::input('telefono');
$alumno->celular = Request::input('celular');
$alumno->barrio = Request::input('barrio');
$alumno->estrato = Request::input('estrato');
$alumno->ciudad_resid = Request::input('ciudad_resid');
$alumno->religion = Request::input('religion');
$alumno->email = Request::input('email');
$alumno->facebook = Request::input('facebook');
$alumno->pazysalvo = Request::input('pazysalvo');
$alumno->deuda = Request::input('deuda');
$alumno->save();
$this->sanarInputUser();
$this->checkOrChangeUsername($alumno->user_id);
$yearactual = Year::actual();
$periodo_actual = Periodo::where('actual', true)->where('year_id', $yearactual->id)->first();
$usuario = new User();
$usuario->username = Request::input('username');
$usuario->password = Hash::make(Request::input('password', '123456'));
$usuario->email = Request::input('email2');
$usuario->is_superuser = Request::input('is_superuser', false);
$usuario->periodo_id = $periodo_actual->id;
$usuario->is_active = Request::input('is_active', true);
$usuario->tipo = 'Alumno';
$usuario->save();
$role = Role::where('name', 'Alumno')->get();
$usuario->attachRole($role[0]);
$alumno->user_id = $usuario->id;
$alumno->save();
$alumno->user = $usuario;
if (Request::input('grupo')['id']) {
$grupo_id = Request::input('grupo')['id'];
$matricula = new Matricula();
$matricula->alumno_id = $alumno->id;
$matricula->grupo_id = $grupo_id;
$matricula->matriculado = true;
$matricula->save();
$grupo = Grupo::find($matricula->grupo_id);
$alumno->grupo = $grupo;
}
return $alumno;
} catch (Exception $e) {
return abort('400', $alumno);
//return $e;
}
}