


Common scenario
Users with different roles should be redirected to different dashboards after login
For the sake of simplicity the example is using user model property role as simple string column,
but you can add as many complexity as you need
use RefreshDatabase;
/** @test */
public function test_app_admin_can_login_and_go_to_admin_dashboard()
{
$user = User::factory()->create([
'role' => 'admin'
]);
session()->setPreviousUrl('/login');
$response = $this->post('/login', [
'email' => $user->email,
'password' => 'password',
]);
$response->assertLocation(route('admin.dashboard')); // admin/dashboard
}Code by steps
user model by factorysession to establish a current urlpassword)login with any route as you need, if it's a named route probably it is betterThanks for reading!
Sign up & get tips and tricks
You'll get monthly updates regarding my most recent articles and products.