📅  最后修改于: 2023-12-03 14:43:45.260000             🧑  作者: Mango
Laravel Fortify is a PHP package that provides a simple and efficient way to handle authentication, password reset, and other commonly needed features in web applications built on Laravel framework. It simplifies the implementation of these features and allows developers to focus on building their application's core functionalities.
Laravel Fortify includes the following features:
Laravel Fortify provides a streamlined way to handle user registration. It includes built-in views and routes for registration, as well as validation and storage of user data.
Route::get('/register', [RegisteredUserController::class, 'create'])
->middleware('guest')
->name('register');
Route::post('/register', [RegisteredUserController::class, 'store'])
->middleware('guest');
The package also handles user authentication with a simple and secure login system. It includes views and routes for login along with session management.
Route::get('/login', [AuthenticatedSessionController::class, 'create'])
->middleware('guest')
->name('login');
Route::post('/login', [AuthenticatedSessionController::class, 'store'])
->middleware('guest');
Laravel Fortify provides a convenient way to handle user logout. It includes a logout route that clears the user's session and redirects them to the login page.
Route::post('/logout', [AuthenticatedSessionController::class, 'destroy'])
->middleware('auth')
->name('logout');
The package includes a secure and easy-to-use password reset feature. It provides views and routes for password reset, as well as password validation and hashing.
Route::get('/forgot-password', [PasswordResetLinkController::class, 'create'])
->middleware('guest')
->name('password.request');
Route::post('/forgot-password', [PasswordResetLinkController::class, 'store'])
->middleware('guest')
->name('password.email');
Route::get('/reset-password/{token}', [NewPasswordController::class, 'create'])
->middleware('guest')
->name('password.reset');
Route::post('/reset-password', [NewPasswordController::class, 'store'])
->middleware('guest')
->name('password.update');
Laravel Fortify supports two-factor authentication (2FA) for enhanced security. It provides built-in views and routes for configuring and verifying 2FA options.
Route::get('/two-factor-challenge', [TwoFactorAuthenticatedSessionController::class, 'create'])
->middleware('guest')
->name('two-factor.login');
Route::post('/two-factor-challenge', [TwoFactorAuthenticatedSessionController::class, 'store'])
->middleware(array_filter([
'guest',
fn () => Fortify::enabledFeatures()->contains('two-factor-authentication'),
]));
Route::post('/user/two-factor-authentication', [TwoFactorAuthenticationController::class, 'store'])
->middleware(array_filter([
'auth',
fn () => Fortify::enabledFeatures()->contains('two-factor-authentication'),
]));
Laravel Fortify is a powerful package that makes authentication and related features hassle-free for Laravel developers. With its comprehensive set of features, it simplifies the implementation of user registration, login, logout, password reset, and two-factor authentication. Using Laravel Fortify ensures a secure and efficient authentication system for your web application.
For more information, please refer to the official Laravel Fortify documentation.