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.
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
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
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']), ]; } }
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'); }
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' ]);
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:
RouteServiceProvider::HOME with '/home' (or your own path) and remove the RouteServiceProvider import.$this->middleware(...) calls from the constructor into a static middleware() method and implement HasMiddleware, as shown above.