📜  laravel 8 ui auth - PHP (1)

📅  最后修改于: 2023-12-03 15:02:34.458000             🧑  作者: Mango

Laravel 8 UI Auth - PHP

Laravel 8 UI Auth is a Laravel package that provides the authentication scaffolding for your application. It is a built-in package and is included with a fresh Laravel installation. The package includes views, routes, controllers, and middleware that are necessary for a basic authentication system. Additionally, Laravel 8 UI Auth provides UI components that can be used to build a registration and login form.

Views

Laravel 8 UI Auth provides several views for authentication, including register, login, forgot password, reset password and verify email views. These views are located in the views/auth directory. You can modify these views to match your application's design and layout.

Here is an example of a login form view:

@extends('layouts.app')

@section('content')
    <div class="card">
        <div class="card-header">{{ __('Login') }}</div>

        <div class="card-body">
            <form method="POST" action="{{ route('login') }}">
                @csrf

                <div class="form-group row">
                    <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

                    <div class="col-md-6">
                        <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>

                        @error('email')
                            <span class="invalid-feedback" role="alert">
                                <strong>{{ $message }}</strong>
                            </span>
                        @enderror
                    </div>
                </div>

                <div class="form-group row">
                    <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

                    <div class="col-md-6">
                        <input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="current-password">

                        @error('password')
                            <span class="invalid-feedback" role="alert">
                                <strong>{{ $message }}</strong>
                            </span>
                        @enderror
                    </div>
                </div>

                <div class="form-group row">
                    <div class="col-md-6 offset-md-4">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>

                            <label class="form-check-label" for="remember">
                                {{ __('Remember Me') }}
                            </label>
                        </div>
                    </div>
                </div>

                <div class="form-group row mb-0">
                    <div class="col-md-8 offset-md-4">
                        <button type="submit" class="btn btn-primary">
                            {{ __('Login') }}
                        </button>

                        @if (Route::has('password.request'))
                            <a class="btn btn-link" href="{{ route('password.request') }}">
                                {{ __('Forgot Your Password?') }}
                            </a>
                        @endif
                    </div>
                </div>
            </form>
        </div>
    </div>
@endsection
Routes

Laravel 8 UI Auth provides several routes for authentication, including register, login, logout, forgot password, reset password and verify email routes. These routes are located in the routes/web.php file. You can modify these routes to match your application's URLs.

Here is an example of a login route:

Route::get('/login', [AuthenticatedSessionController::class, 'create'])
    ->middleware('guest')
    ->name('login');

Route::post('/login', [AuthenticatedSessionController::class, 'store'])
    ->middleware('guest');
Controllers

Laravel 8 UI Auth provides several controllers for authentication, including RegisterController, AuthenticatedSessionController, ConfirmablePasswordController, EmailVerificationNotificationController, EmailVerificationPromptController, and NewPasswordController. These controllers are located in the App\Http\Controllers\Auth directory. You can modify these controllers to add custom functionality or to modify the existing functionality.

Middleware

Laravel 8 UI Auth provides middleware for authentication, including Authenticate, RedirectIfAuthenticated, and SubstituteBindings middleware. These middleware are located in the App\Http\Middleware directory. You can modify these middleware to add custom functionality or to modify the existing functionality.

Conclusion

Laravel 8 UI Auth is a built-in package that provides the authentication scaffolding for your Laravel application. It provides views, routes, controllers, and middleware that are necessary for a basic authentication system. Additionally, Laravel 8 UI Auth provides UI components that can be used to build a registration and login form. It is a powerful and flexible package that can be customized to meet the needs of your application.