When the test below is run I get the following error...
The user is not authenticated -- Failed asserting that false is true.
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\Models\Teacher;
public function test_teacher_can_log_in_using_login_form()
{
$teacher = Teacher::find(1);
$credentials = [
'email' => $teacher->email,
'password' => 'password'
];
$response = $this->post('/teacherlogin', $credentials);
$this->assertAuthenticated();
$response->assertRedirect('/teacher/home');
}
Can anyone help me with this please?```
I take it that your Teacher works with the users table supplied with Laravel?
If not you really should consider a user is a user regardless if it's a teacher, student or whatever.
You use roles to determine what kind of user it is with authorization.
Please use three backticks ` to wrap your code to make it readable.
Not the solution but more readable for others who may help you.
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\Models\Teacher;
public function test_teacher_can_log_in_using_login_form()
{
$teacher = Teacher::find(1);
$credentials = [ 'email' => $teacher->email, 'password' => 'password' ];
$response = $this->post('/teacherlogin', $credentials);
$this->assertAuthenticated();
$response->assertRedirect('/teacher/home');
}
Thanks so much for the response Tray2. Much appreciated. I have created separate models for student, teacher and used different guards to control access for each user group.
Annoyingly I am now unsure if I have solved the problem.