When I try to open Studentregister page it opens the default register page of auth().
I'm new in Laravel I m having issues with syntaxes... I have made only one User class having link with role class. (User class is generated through $php artisan auth and foreign key for Role class is added to it.)
Now I want to register different users like student, teacher through studentRegister.blade.php or teacherRegister.blade.php. And I have to fix role_id in student page as 1 and in teacher role id as 2. So what will be the syntax.
created different route for student register and teacher register (web.php) ..
Route::get('student/register','Auth\RegisterController@registerStudent');
Route::get('teacher/register','Auth\RegisterController@registerTeacher');
added role variable and send it to view (Auth/RegisterController.php)
public function registerStudent()
{ $role_id = 1;
return view('auth.register',compact('role_id'));
}
public function registerTeacher()
{ $role_id = 2;
return view('auth.register',compact('role_id'));
}
setted value of hidden input with "role" name (Auth/Register.Blade.php);
<input id="role" type="hidden" name="role" value="{{$role}}">
change fillable variable in user.php so you can fill role field.
protected $fillable = [ 'name', 'email', 'password',role ];
added role to your create function on RegisterController
**(Auth/RegisterController.php)**.
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'role' => $data['role'],
'password' => Hash::make($data['password']),
]);
}
In StudentRegister.blade.php I have added this
<input id="role_id" type="hidden" name="role_id" value="1">
In TeacherRegister.blade.php I have added this
<input id="role_id" type="hidden" name="role_id" value="2">