›
byrcsc/laravel-dev-login · 1.x
Seed two users, configure two profiles, and log in as either one with a click.
This walks through the shortest useful result: two buttons on /dev-login
that log you in as two different accounts. It assumes you have finished
Installation and setup, so the package is installed, its
config is published, and DEV_LOGIN_ENABLED=true is in your .env.
Profiles point at users that already exist. The package never creates one, so put them in your seeder first:
// database/seeders/DatabaseSeeder.php
use App\Models\User;
public function run(): void
{
User::factory()->create([
'name' => 'Avery Admin',
'email' => 'admin@example.com',
]);
User::factory()->create([
'name' => 'Morgan Member',
'email' => 'member@example.com',
]);
}php artisan migrate:fresh --seedOpen config/dev-login.php and fill in the profiles key. The minimal
profile is two lines:
'profiles' => [
'admin' => [
'label' => 'Admin',
'email' => 'admin@example.com',
],
'member' => [
'label' => 'Member',
'email' => 'member@example.com',
],
],The array key is the route parameter, so admin becomes
POST /dev-login/admin. The label is the button text.
Everything else has a default. The profile above uses your application's
default guard, does not remember the login, names no tenant, and fires
Laravel's Login event.
Visit /dev-login. The page shows your application name, the current
environment as a badge, and one button per profile.
Click Admin. You land on /, authenticated as admin@example.com on the
default guard. Click Member and the same guard now holds Morgan, with no
logout step in between.
The buttons carry labels only. No email address appears on the page, so a screenshot of it is not a list of accounts.
Landing on / after every click gets old. A profile can name its own
destination:
'admin' => [
'label' => 'Admin',
'email' => 'admin@example.com',
'redirect' => '/admin/dashboard',
],If a profile names no redirect, the package follows the session's intended
URL instead. Hitting a page behind auth middleware and then clicking a
button lands you back on the page you wanted.
Routes and redirects covers the full order.
Session cookies do not survive a browser restart. Add remember to the
profiles you use most:
'member' => [
'label' => 'Member',
'email' => 'member@example.com',
'remember' => true,
],This hands Laravel's session guard the remember flag, and that guard writes a remember token to the user exactly as a real login does. It is the only write a dev login causes, and it is Laravel's rather than this package's.
Two profiles, two accounts, one click each. From here:
guard, so one page covers an admin guard and a web
guard at once. See Profiles.tenant, and the page groups its buttons under
tenant headings. See Tenancy.resolver, for applications whose users are not
found by email address. See User resolvers.