PHPackages                             spatie/laravel-login-link - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. spatie/laravel-login-link

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

spatie/laravel-login-link
=========================

Quickly login to your local environment

1.6.6(2mo ago)4381.2M—1.6%27[1 PRs](https://github.com/spatie/laravel-login-link/pulls)1MITPHPPHP ^8.3CI passing

Since May 27Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/spatie/laravel-login-link)[ Packagist](https://packagist.org/packages/spatie/laravel-login-link)[ Docs](https://github.com/spatie/laravel-login-link)[ RSS](/packages/spatie-laravel-login-link/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (19)Versions (29)Used By (1)

Quickly login to your local environment
=======================================

[](#quickly-login-to-your-local-environment)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9242ed195ca7b5a1395d887cc972d169b03c64326ad82d14cca76d0c769ead65/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d6c6f67696e2d6c696e6b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-login-link)[![GitHub Tests Action Status](https://camo.githubusercontent.com/3205568e28f495661a02ac0ff06e8ab6f5b6ac0ccf24bfff8640d1271ab380df/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d6c6f67696e2d6c696e6b2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/spatie/laravel-login-link/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/a3578a8e1d3acdb6b28ddf2568459b68c0c12cf8c8e959a25ca76db5efee51a2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d6c6f67696e2d6c696e6b2f7068702d63732d66697865722e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/spatie/laravel-login-link/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/c3178edc2f3d0254898b2cda00aaef65412b0936cbfd1d74f0584bb0d9fff4a6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d6c6f67696e2d6c696e6b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-login-link)

When developing an app that has an admin section (or any non-public section), you'll likely seed test users to login. In large teams that work on many different apps it can be cumbersome to keep track of the right credentials. Is the user account "", or "", or even ""? Is that password "password", or "secret", or something is else? How do I login with a user that has a different role?

This package solves that problem by offering a component that will render a login link. When clicked, that link will log you in.

In your login view, you can add the `x-login-link` component to show the login link. The `@env('local')` will make sure that the links are only rendered in the local environment.

```
@env('local')

@endenv
```

By default, only localhost is allowed. If you want to allow other hosts, you can add them to the `allowed_hosts` config key.

```
'allowed_hosts' => [
    'localhost',
    'example.com',
],
```

Here's what that might look like in the browser:

[![screenshot](https://github.com/spatie/laravel-login-link/raw/main/docs/login.png?raw=true)](https://github.com/spatie/laravel-login-link/blob/main/docs/login.png?raw=true)

It is meant for local development, and probably shouldn't be used in any publicly reachable environment.

Are you a visual learner?
-------------------------

[](#are-you-a-visual-learner)

Here's [a Laracasts video that demonstrates Laravel Login Link](https://laracasts.com/series/small-laravel-packages-big-impact/episodes/2) made by Christoph Rumpel.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/cfef866a47c957fad4eebc10cff0804f6f2104f16588378e0513027741278209/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d6c6f67696e2d6c696e6b2e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-login-link)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer.

```
composer require spatie/laravel-login-link
```

Optionally, you can publish the config file with:

```
php artisan vendor:publish --tag="login-link-config"
```

This is the contents of the published config file:

```
use Spatie\LoginLink\Http\Controllers\LoginLinkController;

return [
    /*
     * Login links will only work in these environments. In all
     * other environments, an exception will be thrown.
     */
    'allowed_environments' => ['local'],

    /*
     * Login links will only work in these hosts. In all
     * other hosts, an exception will be thrown.
     */
    'allowed_hosts' => ['localhost'],

    /*
     * The package will automatically create a user model when trying
     * to log in a user that doesn't exist.
     */
    'automatically_create_missing_users' => true,

    /*
     * The user model that should be logged in. If this is set to `null`
     * we'll take a look at the model used for the `users`
     * provider in config/auth.php
     */
    'user_model' => null,

    /*
     * After a login link is clicked, we'll redirect the user to this route.
     * If it is set to `null`, we'll redirect the user to their last intended/requested url.
     * You can set it to `/`, for making redirect to the root page.
     */
    'redirect_route_name' => null,

    /*
     * The package will register a route that points to this controller. To have fine
     * grained control over what happens when a login link is clicked, you can
     * override this class.
     */
    'login_link_controller' => LoginLinkController::class,

    /*
     * This middleware will be applied on the route
     * that logs in a user via a link.
     */
    'middleware' => ['web'],
];
```

Optionally, you can publish the views using

```
php artisan vendor:publish --tag="login-link-views"
```

Usage
-----

[](#usage)

To render a login link, simply add the `x-login-link` Blade component to your view. We highly recommend to only render it in the `local` environment.

```
@env('local')

@endenv
```

This component will render a link that, when clicked, will log you in. By default, it will redirect you to the last intended/requested url, but you can customize that by specifying a route name in the `redirect_route_name` of the `login-link` config file. You can also specify the redirect URL on the component itself:

```

```

### Specifying the user model to log in

[](#specifying-the-user-model-to-log-in)

By default, it will use the user model class that is specified in the `providers.users.model` key of the `auth` config file. To override this, you can set the `user_model` of the `login-link` config file to the class name of your user model.

The package will log in the first user in the table. You customize that by passing an `email` attribute. The user with that mail address will be logged in.

```

```

Alternatively, you can specify the primary key of the user (in most cases this will be the `id`)

```

```

You can also specify the attributes of the user that needs to be logged in.

```

```

### Customizing the login link

[](#customizing-the-login-link)

By default, the package will display "Developer login" as the text of the login link. You can customize that by passing a `label` attribute.

```

```

A login link will have the [Tailwind](https://tailwindcss.com) class `underline` by default. To customize that, you can pass any css class that you want to the class property. These classes will override the `underline` default.

Here's how you can create a red, underlined link (when using Tailwind CSS).

```

```

### Specifying the login guard

[](#specifying-the-login-guard)

By default, the package will use the default guard. You can specify another guard.

```

```

### Using custom user model to log in

[](#using-custom-user-model-to-log-in)

You can specify the user model to log in by passing the `user_model` attribute to the component.

The user model should implement the `Illuminate\Contracts\Auth\Authenticatable` interface.

Using the `user_model` will use `null` as default for the `guard` attribute.

```

```

### Automatic user creation

[](#automatic-user-creation)

If the user that needs to be logged in does not exist, the package will use the factory of your user model to create the user, and log that new user in.

If you don't want this behaviour, set `automatically_create_missing_users` in the `local-link` config file to `false`.

### Usage with Vue or React and Inertia.js

[](#usage-with-vue-or-react-and-inertiajs)

The package has a built-in component to support Vue or React and InertiaJS. The props are the same of blade component.

Edit the `HandleInertiaRequests` middleware like so:

```
public function share(Request $request): array
{
    return array_merge(parent::share($request), [
        'environment' => app()->environment(),
        // ...
    ]);
}
```

So, if you need to show the button only in your local environment, use the component like so for Vue :

```
import LoginLink from '@/../../vendor/spatie/laravel-login-link/resources/js/login-link.vue';

// or

```

For React, use the component like so:

```
import LoginLink from '@/../../vendor/spatie/laravel-login-link/resources/js/LoginLink';
// or for TypeScript, uncomment the following line
//import LoginLink from '@/../../vendor/spatie/laravel-login-link/resources/ts/LoginLink';

{page.props.environment === 'local' && (

)}

// or

{page.props.environment === 'local' && (

)}
```

### Usage with Js / ...

[](#usage-with-js--)

The package comes with Vue and React support only. When you use any other JS front end framework to render your views, you can still make use of the package.

You should send a `POST` request to `/laravel-login-link-login`. If you don't give it any payload, then it will log in the first user in your users table. If there is no user, it will be created.

Optionally, you can post any of these payload fields. The functionality of these payloads fields match those of the attributes that you can pass to `x-login-link` component.

- `email`: attempt to log in the user with the given email address
- `key`: attempt to log in the user with the given key (in most cases the `id` of the users)
- `redirect_url`: to which URL should we redirect after logging in
- `user_attributes`: an array containing the attributes that the user that will be logged in needs to have.

Since this is a POST request, make sure to pass a CSRF token as well.

### Usage in other environments

[](#usage-in-other-environments)

Out of the box, the login link will only work in a local environment. If you want to use it other environments, set the `allowed_environments` key of the `login-link` config file to the names of those environments.

Beware however, that you should never display login links in any environment that is publicly reachable, as it will allow anyone to log in.

### Usage on other hosts

[](#usage-on-other-hosts)

Out of the box, the login link will only work on localhost. If you want to use it on other hosts, set the `allowed_hosts` key of the `login-link` config file to the names of those hosts.

Note, however, that you should never display login links on any host that is publicly reachable, as it will allow anyone to log in.

How the package works under the hood
------------------------------------

[](#how-the-package-works-under-the-hood)

[Povilas Korop](https://twitter.com/povilaskorop) of [Laravel Daily](https://laraveldaily.com) made [a nice video on the internals of the package](https://www.youtube.com/watch?v=TN0NKHVeWGc).

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

66

—

FairBetter than 99% of packages

Maintenance87

Actively maintained with recent releases

Popularity60

Solid adoption and visibility

Community28

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 59.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~59 days

Recently: every ~84 days

Total

24

Last Release

80d ago

Major Versions

0.0.3 → 1.0.02022-05-30

PHP version history (4 changes)0.0.1PHP ^8.1

1.0.1PHP ^8.0

1.6.5PHP ^8.2

1.6.6PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (116 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (14 commits)")[![fouteox](https://avatars.githubusercontent.com/u/88294294?v=4)](https://github.com/fouteox "fouteox (13 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (11 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (6 commits)")[![davidjr82](https://avatars.githubusercontent.com/u/4275886?v=4)](https://github.com/davidjr82 "davidjr82 (5 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (5 commits)")[![masterix21](https://avatars.githubusercontent.com/u/6555012?v=4)](https://github.com/masterix21 "masterix21 (5 commits)")[![yparitcher](https://avatars.githubusercontent.com/u/38916402?v=4)](https://github.com/yparitcher "yparitcher (2 commits)")[![negoziator](https://avatars.githubusercontent.com/u/2228675?v=4)](https://github.com/negoziator "negoziator (2 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (2 commits)")[![patrick-levesque](https://avatars.githubusercontent.com/u/16340194?v=4)](https://github.com/patrick-levesque "patrick-levesque (2 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (2 commits)")[![VenomXL](https://avatars.githubusercontent.com/u/102675524?v=4)](https://github.com/VenomXL "VenomXL (2 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![liamja](https://avatars.githubusercontent.com/u/962914?v=4)](https://github.com/liamja "liamja (1 commits)")[![gruzker](https://avatars.githubusercontent.com/u/18495260?v=4)](https://github.com/gruzker "gruzker (1 commits)")[![sdebacker](https://avatars.githubusercontent.com/u/134503?v=4)](https://github.com/sdebacker "sdebacker (1 commits)")[![chapeupreto](https://avatars.githubusercontent.com/u/834048?v=4)](https://github.com/chapeupreto "chapeupreto (1 commits)")[![otherpaco](https://avatars.githubusercontent.com/u/27810032?v=4)](https://github.com/otherpaco "otherpaco (1 commits)")

---

Tags

authenticationdeveloperlaravellocalphptoolsspatielaravellaravel-login-link

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/spatie-laravel-login-link/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-login-link/health.svg)](https://phpackages.com/packages/spatie-laravel-login-link)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[spatie/laravel-passkeys

Use passkeys in your Laravel app

444494.4k16](/packages/spatie-laravel-passkeys)[jeffgreco13/filament-breezy

A custom package for Filament with login flow, profile and teams support.

1.0k1.7M41](/packages/jeffgreco13-filament-breezy)[spatie/laravel-one-time-passwords

Use one-time passwords (OTP) to authenticate in your Laravel app

170223.1k3](/packages/spatie-laravel-one-time-passwords)[ryangjchandler/laravel-cloudflare-turnstile

A simple package to help integrate Cloudflare Turnstile.

438896.6k2](/packages/ryangjchandler-laravel-cloudflare-turnstile)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
