Auth

Based on Laravel's UI package this Auth package is a stripped down version with zero assumptions of your front-end framework choices. It uses simple authentication measures and basic form handling.

Make Auth

Exactly the way it works in Laravel UI. We run the following command to create our auth stubs.

php artisan make:auth

This will add all the files needed and append the required authentication routes to our routes/web.php file:

\Grafite\Auth\Facades\GrafiteAuth::routes([
    'login' => true,
    'logout' => true,
    'register' => true,
    'reset' => true,
    'confirm' => true,
    'verify' => true,
]);

Route::get('/home', [\App\Http\Controllers\HomeController::class, 'index'])->name('home');

Pass the --force flag to overwrite existing views and the HomeController without being prompted.

php artisan make:auth --force

Scaffold Controllers

If you only need the authentication controllers scaffolded into app/Http/Controllers/Auth, run the command below. Note that it replaces any existing controllers in that directory.

php artisan auth:controllers

Controller Middleware

The generated controllers implement Laravel's HasMiddleware interface rather than registering middleware in their constructors. To change a controller's middleware, edit its static middleware() method.

use Illuminate\Routing\Controllers\HasMiddleware;
use Illuminate\Routing\Controllers\Middleware;

class LoginController extends Controller implements HasMiddleware
{
    public static function middleware(): array
    {
        return [
            new Middleware('guest', except: ['logout']),
            new Middleware('auth', only: ['logout']),
        ];
    }
}

Redirects

After logging in, registering, confirming a password, resetting a password or verifying an email, users are redirected to /home. Each generated controller sets this with a $redirectTo property, which you can change.

protected $redirectTo = '/dashboard';

For dynamic redirects, define a redirectTo() method on the controller. It takes precedence over the property.

protected function redirectTo()
{
    return route('dashboard');
}

Middlewares

You can also define middlewares as the second parameter in the routes() method, which will apply to the POST routes in this collection.

\Grafite\Auth\Facades\GrafiteAuth::routes([
    'login' => true,
    'logout' => true,
    'register' => true,
    'reset' => true,
    'confirm' => true,
    'verify' => true,
], [
    'throttle:5,1'
]);

Upgrading to v1.3

Controllers you generated with earlier versions are not updated automatically. If you haven't customized them, re-run php artisan auth:controllers to replace them with the new stubs. Otherwise, update them by hand:

  • Replace RouteServiceProvider::HOME with '/home' (or your own path) and remove the RouteServiceProvider import.
  • Move any $this->middleware(...) calls from the constructor into a static middleware() method and implement HasMiddleware, as shown above.