›
›
›
  1. docs
  2. ›
  3. byrcsc/laravel-dev-login
1.x
Browse documentationOpenClose

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Profiles
  • Safety gates
  • The login flow

Extending

  • User resolvers
  • Tenancy
  • Routes and redirects
  • Customizing the page

Reference

  • Configuration
  • Testing
  • Troubleshooting

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Profiles
  • Safety gates
  • The login flow

Extending

  • User resolvers
  • Tenancy
  • Routes and redirects
  • Customizing the page

Reference

  • Configuration
  • Testing
  • Troubleshooting

byrcsc/laravel-dev-login · 1.x

Quick start.

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.

1. Seed the users the profiles will point at

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 --seed

2. Add two profiles

Open 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.

3. Click a button

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.

4. Land somewhere useful

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.

5. Stay logged in across restarts

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.

What you have

Two profiles, two accounts, one click each. From here:

  • A profile can name a guard, so one page covers an admin guard and a web guard at once. See Profiles.
  • A profile can name a tenant, and the page groups its buttons under tenant headings. See Tenancy.
  • A profile can name a resolver, for applications whose users are not found by email address. See User resolvers.

What to read next

  • Profiles for every key a profile accepts and what each does.
  • The login flow for what happens between the click and the redirect.
  • Troubleshooting if a button throws or the page 404s.
PreviousInstallation and setupNextProfiles
View source

On this page

  1. 1. Seed the users the profiles will point at
  2. 2. Add two profiles
  3. 3. Click a button
  4. 4. Land somewhere useful
  5. 5. Stay logged in across restarts
  6. What you have
  7. What to read next