Skip to content

Commit 7e4205f

Browse files
committed
Merge branch '8.x' into master
# Conflicts: # releases.md # upgrade.md
2 parents ccff594 + c0c19c6 commit 7e4205f

33 files changed

+167
-356
lines changed

authentication.md

Lines changed: 23 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
- [Authenticating](#included-authenticating)
99
- [Retrieving The Authenticated User](#retrieving-the-authenticated-user)
1010
- [Protecting Routes](#protecting-routes)
11-
- [Password Confirmation](#password-confirmation)
1211
- [Login Throttling](#login-throttling)
1312
- [Manually Authenticating Users](#authenticating-users)
1413
- [Remembering Users](#remembering-users)
@@ -28,8 +27,6 @@
2827
<a name="introduction"></a>
2928
## Introduction
3029

31-
> {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-
3330
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.
3431

3532
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
3835

3936
Don't worry if this all sounds confusing now! Many applications will never need to modify the default authentication configuration.
4037

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!
41+
4142
<a name="introduction-database-considerations"></a>
4243
### Database Considerations
4344

@@ -53,90 +54,50 @@ Also, you should verify that your `users` (or equivalent) table contains a nulla
5354
<a name="included-routing"></a>
5455
### Routing
5556

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:
5758

58-
composer require laravel/ui
59+
composer require laravel/jetstream
5960

60-
php artisan ui vue --auth
61+
// Install Jetstream with the Livewire stack...
62+
php artisan jetstream:install livewire
6163

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
6366

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.
6568

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).
6770

6871
#### Creating Applications Including Authentication
6972

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:
7174

72-
laravel new blog --auth
75+
laravel new kitetail --jet
7376

7477
<a name="included-views"></a>
7578
### Views
7679

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.
7881

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.
8083

8184
<a name="included-authenticating"></a>
8285
### Authenticating
8386

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.
8588

8689
#### Path Customization
8790

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`:
8992

9093
public const HOME = '/home';
9194

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`.
13596

13697
<a name="retrieving-the-authenticated-user"></a>
13798
### Retrieving The Authenticated User
13899

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:
140101

141102
use Illuminate\Support\Facades\Auth;
142103

@@ -146,7 +107,7 @@ You may access the authenticated user via the `Auth` facade:
146107
// Get the currently authenticated user's ID...
147108
$id = Auth::id();
148109

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:
150111

151112
<?php
152113

@@ -220,28 +181,15 @@ When attaching the `auth` middleware to a route, you may also specify which guar
220181
$this->middleware('auth:api');
221182
}
222183

223-
<a name="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-
236184
<a name="login-throttling"></a>
237185
### Login Throttling
238186

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.
240188

241189
<a name="authenticating-users"></a>
242190
## Manually Authenticating Users
243191

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!
245193

246194
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:
247195

@@ -313,8 +261,6 @@ If you would like to provide "remember me" functionality in your application, yo
313261
// The user is being remembered...
314262
}
315263

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-
318264
If you are "remembering" users, you may use the `viaRemember` method to determine if the user was authenticated using the "remember me" cookie:
319265

320266
if (Auth::viaRemember()) {

authorization.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ If you would like to provide your own policy discovery logic, you may register a
251251
// return policy class name...
252252
});
253253

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.
255255
256256
<a name="writing-policies"></a>
257257
## Writing Policies
@@ -548,19 +548,19 @@ You may also determine if a user has any authorization ability from a given list
548548

549549
@canany(['update', 'view', 'delete'], $post)
550550
// The current user can update, view, or delete the post
551-
@elsecanany(['create'], \App\Models\::class)
551+
@elsecanany(['create'], \App\Models\Post::class)
552552
// The current user can create a post
553553
@endcanany
554554

555555
#### Actions That Don't Require Models
556556

557557
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:
558558

559-
@can('create', App\Models\::class)
559+
@can('create', App\Models\Post::class)
560560
<!-- The Current User Can Create Posts -->
561561
@endcan
562562

563-
@cannot('create', App\Models\::class)
563+
@cannot('create', App\Models\Post::class)
564564
<!-- The Current User Can't Create Posts -->
565565
@endcannot
566566

blade.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,25 @@ Once your component has been registered, it may be rendered using its tag alias:
517517

518518
<x-package-alert/>
519519

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:
521+
522+
use Illuminate\Support\Facades\Blade;
523+
524+
/**
525+
* Bootstrap your package's services.
526+
*/
527+
public function boot()
528+
{
529+
Blade::componentNamespace('Nightshade\\Views\\Components', 'nightshade');
530+
}
531+
532+
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.
538+
520539
<a name="displaying-components"></a>
521540
### Displaying Components
522541

configuration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ To enable maintenance mode, execute the `down` Artisan command:
136136

137137
php artisan down
138138

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:
140140

141-
php artisan down --message="Upgrading Database" --retry=60
141+
php artisan down --retry=60
142142

143143
#### Bypassing Maintenance Mode
144144

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:
146146

147147
php artisan down --secret="1630542a-246b-4b66-afa1-dd72a4c43515"
148148

contributions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ The Laravel source code is managed on GitHub, and there are repositories for eac
3535
- [Laravel Homestead](https://github.com/laravel/homestead)
3636
- [Laravel Homestead Build Scripts](https://github.com/laravel/settler)
3737
- [Laravel Horizon](https://github.com/laravel/horizon)
38+
- [Laravel Jetstream](https://github.com/laravel/jetstream)
3839
- [Laravel Passport](https://github.com/laravel/passport)
3940
- [Laravel Sanctum](https://github.com/laravel/sanctum)
4041
- [Laravel Scout](https://github.com/laravel/scout)
4142
- [Laravel Socialite](https://github.com/laravel/socialite)
4243
- [Laravel Telescope](https://github.com/laravel/telescope)
4344
- [Laravel Website](https://github.com/laravel/laravel.com-next)
44-
- [Laravel UI](https://github.com/laravel/ui)
4545
</div>
4646

4747
<a name="support-questions"></a>

0 commit comments

Comments
 (0)