Skip to content

Commit bb0d238

Browse files
committed
fix conflicts
2 parents 8c527b5 + ecc940f commit bb0d238

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+5022
-1416
lines changed

Diff for: artisan.md

+18-5
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ php artisan vendor:publish --provider="Laravel\Tinker\TinkerServiceProvider"
8686
<a name="command-allow-list"></a>
8787
#### Command Allow List
8888

89-
Tinker utilizes an "allow" list to determine which Artisan commands are allowed to be run within its shell. By default, you may run the `clear-compiled`, `down`, `env`, `inspire`, `migrate`, `optimize`, and `up` commands. If you would like to allow more commands you may add them to the `commands` array in your `tinker.php` configuration file:
89+
Tinker utilizes an "allow" list to determine which Artisan commands are allowed to be run within its shell. By default, you may run the `clear-compiled`, `down`, `env`, `inspire`, `migrate`, `migrate:install`, `up`, and `optimize` commands. If you would like to allow more commands you may add them to the `commands` array in your `tinker.php` configuration file:
9090

9191
'commands' => [
9292
// App\Console\Commands\ExampleCommand::class,
@@ -158,12 +158,25 @@ Let's take a look at an example command. Note that we are able to request any de
158158
> [!NOTE]
159159
> For greater code reuse, it is good practice to keep your console commands light and let them defer to application services to accomplish their tasks. In the example above, note that we inject a service class to do the "heavy lifting" of sending the e-mails.
160160
161+
<a name="exit-codes"></a>
162+
#### Exit Codes
163+
164+
If nothing is returned from the `handle` method and the command executes successfully, the command will exit with a `0` exit code, indicating success. However, the `handle` method may optionally return an integer to manually specify command's exit code:
165+
166+
$this->error('Something went wrong.');
167+
168+
return 1;
169+
170+
If you would like to "fail" the command from any method within the command, you may utilize the `fail` method. The `fail` method will immediately terminate execution of the command and return an exit code of `1`:
171+
172+
$this->fail('Something went wrong.');
173+
161174
<a name="closure-commands"></a>
162175
### Closure Commands
163176

164177
Closure based commands provide an alternative to defining console commands as classes. In the same way that route closures are an alternative to controllers, think of command closures as an alternative to command classes.
165178

166-
Even though the `routes/console.php` file file does not define HTTP routes, it defines console based entry points (routes) into your application. Within this file, you may define all of your closure based console commands using the `Artisan::command` method. The `command` method accepts two arguments: the [command signature](#defining-input-expectations) and a closure which receives the command's arguments and options:
179+
Even though the `routes/console.php` file does not define HTTP routes, it defines console based entry points (routes) into your application. Within this file, you may define all of your closure based console commands using the `Artisan::command` method. The `command` method accepts two arguments: the [command signature](#defining-input-expectations) and a closure which receives the command's arguments and options:
167180

168181
Artisan::command('mail:send {user}', function (string $user) {
169182
$this->info("Sending email to: {$user}!");
@@ -636,7 +649,7 @@ Sometimes, you may need more manual control over how a progress bar is advanced.
636649

637650
$bar->finish();
638651

639-
> [!NOTE]
652+
> [!NOTE]
640653
> For more advanced options, check out the [Symfony Progress Bar component documentation](https://symfony.com/doc/7.0/components/console/helpers/progressbar.html).
641654
642655
<a name="registering-commands"></a>
@@ -645,7 +658,7 @@ Sometimes, you may need more manual control over how a progress bar is advanced.
645658
By default, Laravel automatically registers all commands within the `app/Console/Commands` directory. However, you can instruct Laravel to scan other directories for Artisan commands using the `withCommands` method in your application's `bootstrap/app.php` file:
646659

647660
->withCommands([
648-
__DIR__.'../app/Domain/Orders/Commands',
661+
__DIR__.'/../app/Domain/Orders/Commands',
649662
])
650663

651664
If necessary, you may also manually register commands by providing the command's class name to the `withCommands` method:
@@ -656,7 +669,7 @@ If necessary, you may also manually register commands by providing the command's
656669
SendEmails::class,
657670
])
658671

659-
When Artisan boots, all the commands in your application will be resolved by the [service container](/docs/{{version}}/container) and registered with Artisan.
672+
When Artisan boots, all the commands in your application will be resolved by the [service container](/docs/{{version}}/container) and registered with Artisan.
660673

661674
<a name="programmatically-executing-commands"></a>
662675
## Programmatically Executing Commands

Diff for: authentication.md

+47-21
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- [Adding Custom User Providers](#adding-custom-user-providers)
2626
- [The User Provider Contract](#the-user-provider-contract)
2727
- [The Authenticatable Contract](#the-authenticatable-contract)
28+
- [Automatic Password Rehashing](#automatic-password-rehashing)
2829
- [Social Authentication](/docs/{{version}}/socialite)
2930
- [Events](#events)
3031

@@ -52,7 +53,9 @@ Want to get started fast? Install a [Laravel application starter kit](/docs/{{ve
5253
<a name="introduction-database-considerations"></a>
5354
### Database Considerations
5455

55-
By default, Laravel includes an `App\Models\User` [Eloquent model](/docs/{{version}}/eloquent) in your `app/Models` directory. This model may be used with the default Eloquent authentication driver. If your application is not using Eloquent, you may use the `database` authentication provider which uses the Laravel query builder.
56+
By default, Laravel includes an `App\Models\User` [Eloquent model](/docs/{{version}}/eloquent) in your `app/Models` directory. This model may be used with the default Eloquent authentication driver.
57+
58+
If your application is not using Eloquent, you may use the `database` authentication provider which uses the Laravel query builder. If your application is using MongoDB, check out MongoDB's official [Laravel user authentication documentation](https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/user-authentication/) .
5659

5760
When building the database schema for the `App\Models\User` model, make sure the password column is at least 60 characters in length. Of course, the `users` table migration that is included in new Laravel applications already creates a column that exceeds this length.
5861

@@ -181,7 +184,7 @@ To determine if the user making the incoming HTTP request is authenticated, you
181184
<a name="protecting-routes"></a>
182185
### Protecting Routes
183186

184-
[Route middleware](/docs/{{version}}/middleware) can be used to only allow authenticated users to access a given route. Laravel ships with an `auth` middleware, which is a [middleware alias](/docs/{{version}}/middleware#middleware-alias) for the `Illuminate\Auth\Middleware\Authenticate` class. Since this middleware is already aliased internally by Laravel, all you need to do is attach the middleware to a route definition:
187+
[Route middleware](/docs/{{version}}/middleware) can be used to only allow authenticated users to access a given route. Laravel ships with an `auth` middleware, which is a [middleware alias](/docs/{{version}}/middleware#middleware-aliases) for the `Illuminate\Auth\Middleware\Authenticate` class. Since this middleware is already aliased internally by Laravel, all you need to do is attach the middleware to a route definition:
185188

186189
Route::get('/flights', function () {
187190
// Only authenticated users may access this route...
@@ -279,8 +282,8 @@ For complex query conditions, you may provide a closure in your array of credent
279282
use Illuminate\Database\Eloquent\Builder;
280283

281284
if (Auth::attempt([
282-
'email' => $email,
283-
'password' => $password,
285+
'email' => $email,
286+
'password' => $password,
284287
fn (Builder $query) => $query->has('activeSubscription'),
285288
])) {
286289
// Authentication was successful...
@@ -359,9 +362,9 @@ To authenticate a user using their database record's primary key, you may use th
359362

360363
Auth::loginUsingId(1);
361364

362-
You may pass a boolean value as the second argument to the `loginUsingId` method. This value indicates if "remember me" functionality is desired for the authenticated session. Remember, this means that the session will be authenticated indefinitely or until the user manually logs out of the application:
365+
You may pass a boolean value to the `remember` argument of the `loginUsingId` method. This value indicates if "remember me" functionality is desired for the authenticated session. Remember, this means that the session will be authenticated indefinitely or until the user manually logs out of the application:
363366

364-
Auth::loginUsingId(1, $remember = true);
367+
Auth::loginUsingId(1, remember: true);
365368

366369
<a name="authenticate-a-user-once"></a>
367370
#### Authenticate a User Once
@@ -457,7 +460,7 @@ In addition to calling the `logout` method, it is recommended that you invalidat
457460

458461
Laravel also provides a mechanism for invalidating and "logging out" a user's sessions that are active on other devices without invalidating the session on their current device. This feature is typically utilized when a user is changing or updating their password and you would like to invalidate sessions on other devices while keeping the current device authenticated.
459462

460-
Before getting started, you should make sure that the `Illuminate\Session\Middleware\AuthenticateSession` middleware is included on the routes that should receive session authentication. Typically, you should place this middleware on a route group definition so that it can be applied to the majority of your application's routes. By default, the `AuthenticateSession` middleware may be attached to a route using the `auth.session` [middleware alias](/docs/{{version}}/middleware#middleware-alias):
463+
Before getting started, you should make sure that the `Illuminate\Session\Middleware\AuthenticateSession` middleware is included on the routes that should receive session authentication. Typically, you should place this middleware on a route group definition so that it can be applied to the majority of your application's routes. By default, the `AuthenticateSession` middleware may be attached to a route using the `auth.session` [middleware alias](/docs/{{version}}/middleware#middleware-aliases):
461464

462465
Route::middleware(['auth', 'auth.session'])->group(function () {
463466
Route::get('/', function () {
@@ -716,22 +719,45 @@ This interface is simple. The `getAuthIdentifierName` method should return the n
716719

717720
This interface allows the authentication system to work with any "user" class, regardless of what ORM or storage abstraction layer you are using. By default, Laravel includes an `App\Models\User` class in the `app/Models` directory which implements this interface.
718721

722+
<a name="automatic-password-rehashing"></a>
723+
## Automatic Password Rehashing
724+
725+
Laravel's default password hashing algorithm is bcrypt. The "work factor" for bcrypt hashes can be adjusted via your application's `config/hashing.php` configuration file or the `BCRYPT_ROUNDS` environment variable.
726+
727+
Typically, the bcrypt work factor should be increased over time as CPU / GPU processing power increases. If you increase the bcrypt work factor for your application, Laravel will gracefully and automatically rehash user passwords as users authenticate with your application via Laravel's starter kits or when you [manually authenticate users](#authenticating-users) via the `attempt` method.
728+
729+
Typically, automatic password rehashing should not disrupt your application; however, you may disable this behavior by publishing the `hashing` configuration file:
730+
731+
```shell
732+
php artisan config:publish hashing
733+
```
734+
735+
Once the configuration file has been published, you may set the `rehash_on_login` configuration value to `false`:
736+
737+
```php
738+
'rehash_on_login' => false,
739+
```
740+
719741
<a name="events"></a>
720742
## Events
721743

722744
Laravel dispatches a variety of [events](/docs/{{version}}/events) during the authentication process. You may [define listeners](/docs/{{version}}/events) for any of the following events:
723745

724-
Event Name |
725-
------------- |
726-
`Illuminate\Auth\Events\Registered` |
727-
`Illuminate\Auth\Events\Attempting` |
728-
`Illuminate\Auth\Events\Authenticated` |
729-
`Illuminate\Auth\Events\Login` |
730-
`Illuminate\Auth\Events\Failed` |
731-
`Illuminate\Auth\Events\Validated` |
732-
`Illuminate\Auth\Events\Verified` |
733-
`Illuminate\Auth\Events\Logout` |
734-
`Illuminate\Auth\Events\CurrentDeviceLogout` |
735-
`Illuminate\Auth\Events\OtherDeviceLogout` |
736-
`Illuminate\Auth\Events\Lockout` |
737-
`Illuminate\Auth\Events\PasswordReset` |
746+
<div class="overflow-auto">
747+
748+
| Event Name |
749+
| --- |
750+
| `Illuminate\Auth\Events\Registered` |
751+
| `Illuminate\Auth\Events\Attempting` |
752+
| `Illuminate\Auth\Events\Authenticated` |
753+
| `Illuminate\Auth\Events\Login` |
754+
| `Illuminate\Auth\Events\Failed` |
755+
| `Illuminate\Auth\Events\Validated` |
756+
| `Illuminate\Auth\Events\Verified` |
757+
| `Illuminate\Auth\Events\Logout` |
758+
| `Illuminate\Auth\Events\CurrentDeviceLogout` |
759+
| `Illuminate\Auth\Events\OtherDeviceLogout` |
760+
| `Illuminate\Auth\Events\Lockout` |
761+
| `Illuminate\Auth\Events\PasswordReset` |
762+
763+
</div>

Diff for: authorization.md

+47-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- [Via Middleware](#via-middleware)
2323
- [Via Blade Templates](#via-blade-templates)
2424
- [Supplying Additional Context](#supplying-additional-context)
25+
- [Authorization & Inertia](#authorization-and-inertia)
2526

2627
<a name="introduction"></a>
2728
## Introduction
@@ -187,7 +188,7 @@ When using the `Gate::authorize` method, which throws an `AuthorizationException
187188

188189
// The action is authorized...
189190

190-
<a name="customising-gate-response-status"></a>
191+
<a name="customizing-gate-response-status"></a>
191192
#### Customizing The HTTP Response Status
192193

193194
When an action is denied via a Gate, a `403` HTTP response is returned; however, it can sometimes be useful to return an alternative HTTP status code. You may customize the HTTP status code returned for a failed authorization check using the `denyWithStatus` static constructor on the `Illuminate\Auth\Access\Response` class:
@@ -240,7 +241,7 @@ You may use the `after` method to define a closure to be executed after all othe
240241
}
241242
});
242243

243-
Similar to the `before` method, if the `after` closure returns a non-null result that result will be considered the result of the authorization check.
244+
Values returned by `after` closures will not override the result of the authorization check unless the gate or policy returned `null`.
244245

245246
<a name="inline-authorization"></a>
246247
### Inline Authorization
@@ -383,7 +384,7 @@ When using the `Gate::authorize` method, which throws an `AuthorizationException
383384

384385
// The action is authorized...
385386

386-
<a name="customising-policy-response-status"></a>
387+
<a name="customizing-policy-response-status"></a>
387388
#### Customizing the HTTP Response Status
388389

389390
When an action is denied via a policy method, a `403` HTTP response is returned; however, it can sometimes be useful to return an alternative HTTP status code. You may customize the HTTP status code returned for a failed authorization check using the `denyWithStatus` static constructor on the `Illuminate\Auth\Access\Response` class:
@@ -606,7 +607,7 @@ As previously discussed, some policy methods like `create` do not require a mode
606607
<a name="via-middleware"></a>
607608
### Via Middleware
608609

609-
Laravel includes a middleware that can authorize actions before the incoming request even reaches your routes or controllers. By default, the `Illuminate\Auth\Middleware\Authorize` middleware may be attached to a route using the `can` [middleware alias](/docs/{{version}}/middleware#middleware-alias), which is automatically registered by Laravel. Let's explore an example of using the `can` middleware to authorize that a user can update a post:
610+
Laravel includes a middleware that can authorize actions before the incoming request even reaches your routes or controllers. By default, the `Illuminate\Auth\Middleware\Authorize` middleware may be attached to a route using the `can` [middleware alias](/docs/{{version}}/middleware#middleware-aliases), which is automatically registered by Laravel. Let's explore an example of using the `can` middleware to authorize that a user can update a post:
610611

611612
use App\Models\Post;
612613

@@ -728,3 +729,45 @@ When attempting to determine if the authenticated user can update a given post,
728729

729730
return redirect('/posts');
730731
}
732+
733+
<a name="authorization-and-inertia"></a>
734+
## Authorization & Inertia
735+
736+
Although authorization must always be handled on the server, it can often be convenient to provide your frontend application with authorization data in order to properly render your application's UI. Laravel does not define a required convention for exposing authorization information to an Inertia powered frontend.
737+
738+
However, if you are using one of Laravel's Inertia-based [starter kits](/docs/{{version}}/starter-kits), your application already contains a `HandleInertiaRequests` middleware. Within this middleware's `share` method, you may return shared data that will be provided to all Inertia pages in your application. This shared data can serve as a convenient location to define authorization information for the user:
739+
740+
```php
741+
<?php
742+
743+
namespace App\Http\Middleware;
744+
745+
use App\Models\Post;
746+
use Illuminate\Http\Request;
747+
use Inertia\Middleware;
748+
749+
class HandleInertiaRequests extends Middleware
750+
{
751+
// ...
752+
753+
/**
754+
* Define the props that are shared by default.
755+
*
756+
* @return array<string, mixed>
757+
*/
758+
public function share(Request $request)
759+
{
760+
return [
761+
...parent::share($request),
762+
'auth' => [
763+
'user' => $request->user(),
764+
'permissions' => [
765+
'post' => [
766+
'create' => $request->user()->can('create', Post::class),
767+
],
768+
],
769+
],
770+
];
771+
}
772+
}
773+
```

0 commit comments

Comments
 (0)