You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> {tip} **Want to get started fast?** Install the `laravel/ui` Composer package and run `php artisan ui vue --auth` in a fresh Laravel application. After migrating your database, navigate your browser to `http://your-app.test/register` or any other URL that is assigned to your application. These commands will take care of scaffolding your entire authentication system!
32
-
33
30
Laravel makes implementing authentication very simple. In fact, almost everything is configured for you out of the box. The authentication configuration file is located at `config/auth.php`, which contains several well documented options for tweaking the behavior of the authentication services.
34
31
35
32
At its core, Laravel's authentication facilities are made up of "guards" and "providers". Guards define how users are authenticated for each request. For example, Laravel ships with a `session` guard which maintains state using session storage and cookies.
@@ -38,6 +35,10 @@ Providers define how users are retrieved from your persistent storage. Laravel s
38
35
39
36
Don't worry if this all sounds confusing now! Many applications will never need to modify the default authentication configuration.
40
37
38
+
#### Getting Started Fast
39
+
40
+
Want to get started fast? Install [Laravel Jetstream](https://jetstream.laravel.com) in a fresh Laravel application. After migrating your database, navigate your browser to `/register` or any other URL that is assigned to your application. Jetstream will take care of scaffolding your entire authentication system!
@@ -53,90 +54,50 @@ Also, you should verify that your `users` (or equivalent) table contains a nulla
53
54
<aname="included-routing"></a>
54
55
### Routing
55
56
56
-
Laravel's `laravel/ui` package provides a quick way to scaffold all of the routes and views you need for authentication using a few simple commands:
57
+
Laravel's `laravel/jetstream` package provides a quick way to scaffold all of the routes and views you need for authentication using a few simple commands:
57
58
58
-
composer require laravel/ui
59
+
composer require laravel/jetstream
59
60
60
-
php artisan ui vue --auth
61
+
// Install Jetstream with the Livewire stack...
62
+
php artisan jetstream:install livewire
61
63
62
-
This command should be used on fresh applications and will install a layout view, registration and login views, as well as routes for all authentication end-points. A `HomeController` will also be generated to handle post-login requests to your application's dashboard.
64
+
// Install Jetstream with the Inertia stack...
65
+
php artisan jetstream:install inertia
63
66
64
-
The `laravel/ui` package also generates several pre-built authentication controllers, which are located in the `App\Http\Controllers\Auth` namespace. The `RegisterController` handles new user registration, the `LoginController` handles authentication, the `ForgotPasswordController` handles e-mailing links for resetting passwords, and the `ResetPasswordController` contains the logic to reset passwords. Each of these controllers uses a trait to include their necessary methods. For many applications, you will not need to modify these controllers at all.
67
+
This command should be used on fresh applications and will install a layout view, registration and login views, as well as routes for all authentication end-points. A `/dashboard` route will also be generated to handle post-login requests to your application's dashboard.
65
68
66
-
> {tip} If your application doesn’t need registration, you may disable it by removing the newly created `RegisterController` and modifying your route declaration: `Auth::routes(['register' => false]);`.
69
+
To learn more about Jetstream, please visit the official [Jetstream documentation](https://jetstream.laravel.com).
67
70
68
71
#### Creating Applications Including Authentication
69
72
70
-
If you are starting a brand new application and would like to include the authentication scaffolding, you may use the `--auth` directive when creating your application. This command will create a new application with all of the authentication scaffolding compiled and installed:
73
+
If you are starting a brand new application and would like to include the authentication scaffolding, you may use the `--jet` directive when creating your application via the Laravel Installer. This command will create a new application with all of the authentication scaffolding compiled and installed:
71
74
72
-
laravel new blog --auth
75
+
laravel new kitetail --jet
73
76
74
77
<aname="included-views"></a>
75
78
### Views
76
79
77
-
As mentioned in the previous section, the `laravel/ui` package's `php artisan ui vue --auth` command will create all of the views you need for authentication and place them in the `resources/views/auth` directory.
80
+
As mentioned in the previous section, the `laravel/jetstream` package's `php artisan jetstream:install` command will create all of the views you need for authentication and place them in the `resources/views/auth` directory.
78
81
79
-
The `ui` command will also create a `resources/views/layouts` directory containing a base layout for your application. All of these views use the Bootstrap CSS framework, but you are free to customize them however you wish.
82
+
Jetstream will also create a `resources/views/layouts` directory containing a base layout for your application. All of these views use the Tailwind CSS framework, but you are free to customize them however you wish.
80
83
81
84
<aname="included-authenticating"></a>
82
85
### Authenticating
83
86
84
-
Now that you have routes and views setup for the included authentication controllers, you are ready to register and authenticate new users for your application! You may access your application in a browser since the authentication controllers already contain the logic (via their traits) to authenticate existing users and store new users in the database.
87
+
Now that you have routes and views setup for the included authentication controllers, you are ready to register and authenticate new users for your application! You may access your application in a browser since Jetstream's authentication controllers already contain the logic to authenticate existing users and store new users in the database.
85
88
86
89
#### Path Customization
87
90
88
-
When a user is successfully authenticated, they will be redirected to the `/home` URI. You can customize the post-authentication redirect path using the `HOME` constant defined in your `RouteServiceProvider`:
91
+
When a user is successfully authenticated, they will typically be redirected to the `/home` URI. You can customize the post-authentication redirect path using the `HOME` constant defined in your `RouteServiceProvider`:
89
92
90
93
public const HOME = '/home';
91
94
92
-
If you need more robust customization of the response returned when a user is authenticated, Laravel provides an empty `authenticated(Request $request, $user)` method within the `AuthenticatesUsers` trait. This trait is used by the `LoginController` class that is installed into your application when using the `laravel/ui` package. Therefore, you can define your own `authenticated` method within the `LoginController` class:
93
-
94
-
/**
95
-
* The user has been authenticated.
96
-
*
97
-
* @param \Illuminate\Http\Request $request
98
-
* @param mixed $user
99
-
* @return mixed
100
-
*/
101
-
protected function authenticated(Request $request, $user)
102
-
{
103
-
return response([
104
-
//
105
-
]);
106
-
}
107
-
108
-
#### Username Customization
109
-
110
-
By default, Laravel uses the `email` field for authentication. If you would like to customize this, you may define a `username` method on your `LoginController`:
111
-
112
-
public function username()
113
-
{
114
-
return 'username';
115
-
}
116
-
117
-
#### Guard Customization
118
-
119
-
You may also customize the "guard" that is used to authenticate and register users. To get started, define a `guard` method on your `LoginController`, `RegisterController`, and `ResetPasswordController`. The method should return a guard instance:
120
-
121
-
use Illuminate\Support\Facades\Auth;
122
-
123
-
protected function guard()
124
-
{
125
-
return Auth::guard('guard-name');
126
-
}
127
-
128
-
#### Validation / Storage Customization
129
-
130
-
To modify the form fields that are required when a new user registers with your application, or to customize how new users are stored into your database, you may modify the `RegisterController` class. This class is responsible for validating and creating new users of your application.
131
-
132
-
The `validator` method of the `RegisterController` contains the validation rules for new users of the application. You are free to modify this method as you wish.
133
-
134
-
The `create` method of the `RegisterController` is responsible for creating new `App\Models\User` records in your database using the [Eloquent ORM](/docs/{{version}}/eloquent). You are free to modify this method according to the needs of your database.
95
+
When using Laravel Jetstream, the Jetstream installation process will change the value of the `HOME` constant to `/dashboard`.
135
96
136
97
<aname="retrieving-the-authenticated-user"></a>
137
98
### Retrieving The Authenticated User
138
99
139
-
You may access the authenticated user via the `Auth` facade:
100
+
While handling an incoming request, you may access the authenticated user via the `Auth` facade:
140
101
141
102
use Illuminate\Support\Facades\Auth;
142
103
@@ -146,7 +107,7 @@ You may access the authenticated user via the `Auth` facade:
146
107
// Get the currently authenticated user's ID...
147
108
$id = Auth::id();
148
109
149
-
Alternatively, once a user is authenticated, you may access the authenticated user via an `Illuminate\Http\Request` instance. Remember, type-hinted classes will automatically be injected into your controller methods:
110
+
Alternatively, once a user is authenticated, you may access the authenticated user via an `Illuminate\Http\Request` instance. Remember, type-hinted classes will automatically be injected into your controller methods. By type-hinting the `Illuminate\Http\Request` object, you may gain convenient access to the authenticated user from any controller method in your application:
150
111
151
112
<?php
152
113
@@ -220,28 +181,15 @@ When attaching the `auth` middleware to a route, you may also specify which guar
220
181
$this->middleware('auth:api');
221
182
}
222
183
223
-
<aname="password-confirmation"></a>
224
-
### Password Confirmation
225
-
226
-
Sometimes, you may wish to require the user to confirm their password before accessing a specific area of your application. For example, you may require this before the user modifies any billing settings within the application.
227
-
228
-
To accomplish this, Laravel provides a `password.confirm` middleware. Attaching the `password.confirm` middleware to a route will redirect users to a screen where they need to confirm their password before they can continue:
229
-
230
-
Route::get('/settings/security', function () {
231
-
// Users must confirm their password before continuing...
232
-
})->middleware(['auth', 'password.confirm']);
233
-
234
-
After the user has successfully confirmed their password, the user is redirected to the route they originally tried to access. By default, after confirming their password, the user will not have to confirm their password again for three hours. You are free to customize the length of time before the user must re-confirm their password using the `auth.password_timeout` configuration option.
235
-
236
184
<aname="login-throttling"></a>
237
185
### Login Throttling
238
186
239
-
If you are using Laravel's built-in `LoginController` class, the `Illuminate\Foundation\Auth\ThrottlesLogins` trait will already be included in your controller. By default, the user will not be able to login for one minute if they fail to provide the correct credentials after several attempts. The throttling is unique to the user's username / e-mail address and their IP address.
187
+
If you are using Laravel Jetstream, rate limiting will automatically be applied to login attempts. By default, the user will not be able to login for one minute if they fail to provide the correct credentials after several attempts. The throttling is unique to the user's username / e-mail address and their IP address.
240
188
241
189
<aname="authenticating-users"></a>
242
190
## Manually Authenticating Users
243
191
244
-
Note that you are not required to use the authentication controllers included with Laravel. If you choose to remove these controllers, you will need to manage user authentication using the Laravel authentication classes directly. Don't worry, it's a cinch!
192
+
Note that you are not required to use the authentication controllers included with Laravel Jetstream. If you choose to not use this scaffolding, you will need to manage user authentication using the Laravel authentication classes directly. Don't worry, it's a cinch!
245
193
246
194
We will access Laravel's authentication services via the `Auth`[facade](/docs/{{version}}/facades), so we'll need to make sure to import the `Auth` facade at the top of the class. Next, let's check out the `attempt` method:
247
195
@@ -313,8 +261,6 @@ If you would like to provide "remember me" functionality in your application, yo
313
261
// The user is being remembered...
314
262
}
315
263
316
-
> {tip} If you are using the built-in `LoginController` that is shipped with Laravel, the proper logic to "remember" users is already implemented by the traits used by the controller.
317
-
318
264
If you are "remembering" users, you may use the `viaRemember` method to determine if the user was authenticated using the "remember me" cookie:
Copy file name to clipboardExpand all lines: authorization.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -251,7 +251,7 @@ If you would like to provide your own policy discovery logic, you may register a
251
251
// return policy class name...
252
252
});
253
253
254
-
> {note} Any policies that are explicitly mapped in your `AuthServiceProvider` will take precedence over any potential auto-discovered policies.
254
+
> {note} Any policies that are explicitly mapped in your `AuthServiceProvider` will take precedence over any potentially auto-discovered policies.
255
255
256
256
<aname="writing-policies"></a>
257
257
## Writing Policies
@@ -548,19 +548,19 @@ You may also determine if a user has any authorization ability from a given list
548
548
549
549
@canany(['update', 'view', 'delete'], $post)
550
550
// The current user can update, view, or delete the post
551
-
@elsecanany(['create'], \App\Models\::class)
551
+
@elsecanany(['create'], \App\Models\Post::class)
552
552
// The current user can create a post
553
553
@endcanany
554
554
555
555
#### Actions That Don't Require Models
556
556
557
557
Like most of the other authorization methods, you may pass a class name to the `@can` and `@cannot` directives if the action does not require a model instance:
Copy file name to clipboardExpand all lines: blade.md
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -517,6 +517,25 @@ Once your component has been registered, it may be rendered using its tag alias:
517
517
518
518
<x-package-alert/>
519
519
520
+
Alternatively, you may use the `componentNamespace` method to autoload component classes by convention. For example, a `Nightshade` package might have `Calendar` and `ColorPicker` components that reside within the `Package\Views\Components` namespace:
This will allow the usage of package components by their vendor namespace using the `package-name::` syntax:
533
+
534
+
<x-nightshade::calendar />
535
+
<x-nightshade::color-picker />
536
+
537
+
Blade will automatically detect the class that's linked to this component by pascal-casing the component name. Subdirectories are also supported using "dot" notation.
Copy file name to clipboardExpand all lines: configuration.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -136,13 +136,13 @@ To enable maintenance mode, execute the `down` Artisan command:
136
136
137
137
php artisan down
138
138
139
-
You may also provide `message` and `retry`options to the `down` command. The `message` value may be used to display or log a custom message, while the `retry` value will be set as the `Retry-After` HTTP header's value:
139
+
You may also provide a `retry`option to the `down` command, which will be set as the `Retry-After` HTTP header's value:
140
140
141
-
php artisan down --message="Upgrading Database" --retry=60
141
+
php artisan down --retry=60
142
142
143
143
#### Bypassing Maintenance Mode
144
144
145
-
Even while in maintenance mode, you may use use the `secret` option to specify a maintenance mode bypass token:
145
+
Even while in maintenance mode, you may use the `secret` option to specify a maintenance mode bypass token:
146
146
147
147
php artisan down --secret="1630542a-246b-4b66-afa1-dd72a4c43515"
0 commit comments