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
use a single indent for multiline ternary statements. this is better than alignment with an arbitrary pattern in the first line because it doesn't need to be shifted as adjustments are made to the code.
along with #10166
Copy file name to clipboardExpand all lines: authorization.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -168,8 +168,8 @@ So far, we have only examined gates that return simple boolean values. However,
168
168
169
169
Gate::define('edit-settings', function (User $user) {
170
170
return $user->isAdmin
171
-
? Response::allow()
172
-
: Response::deny('You must be an administrator.');
171
+
? Response::allow()
172
+
: Response::deny('You must be an administrator.');
173
173
});
174
174
175
175
Even when you return an authorization response from your gate, the `Gate::allows` method will still return a simple boolean value; however, you may use the `Gate::inspect` method to get the full authorization response returned by the gate:
@@ -199,8 +199,8 @@ When an action is denied via a Gate, a `403` HTTP response is returned; however,
199
199
200
200
Gate::define('edit-settings', function (User $user) {
201
201
return $user->isAdmin
202
-
? Response::allow()
203
-
: Response::denyWithStatus(404);
202
+
? Response::allow()
203
+
: Response::denyWithStatus(404);
204
204
});
205
205
206
206
Because hiding resources via a `404` response is such a common pattern for web applications, the `denyAsNotFound` method is offered for convenience:
@@ -211,8 +211,8 @@ Because hiding resources via a `404` response is such a common pattern for web a
211
211
212
212
Gate::define('edit-settings', function (User $user) {
213
213
return $user->isAdmin
214
-
? Response::allow()
215
-
: Response::denyAsNotFound();
214
+
? Response::allow()
215
+
: Response::denyAsNotFound();
216
216
});
217
217
218
218
<aname="intercepting-gate-checks"></a>
@@ -362,8 +362,8 @@ So far, we have only examined policy methods that return simple boolean values.
362
362
public function update(User $user, Post $post): Response
363
363
{
364
364
return $user->id === $post->user_id
365
-
? Response::allow()
366
-
: Response::deny('You do not own this post.');
365
+
? Response::allow()
366
+
: Response::deny('You do not own this post.');
367
367
}
368
368
369
369
When returning an authorization response from your policy, the `Gate::allows` method will still return a simple boolean value; however, you may use the `Gate::inspect` method to get the full authorization response returned by the gate:
@@ -399,8 +399,8 @@ When an action is denied via a policy method, a `403` HTTP response is returned;
399
399
public function update(User $user, Post $post): Response
400
400
{
401
401
return $user->id === $post->user_id
402
-
? Response::allow()
403
-
: Response::denyWithStatus(404);
402
+
? Response::allow()
403
+
: Response::denyWithStatus(404);
404
404
}
405
405
406
406
Because hiding resources via a `404` response is such a common pattern for web applications, the `denyAsNotFound` method is offered for convenience:
@@ -415,8 +415,8 @@ Because hiding resources via a `404` response is such a common pattern for web a
415
415
public function update(User $user, Post $post): Response
Copy file name to clipboardExpand all lines: passwords.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
@@ -74,8 +74,8 @@ Next, we will define a route that handles the form submission request from the "
74
74
);
75
75
76
76
return $status === Password::ResetLinkSent
77
-
? back()->with(['status' => __($status)])
78
-
: back()->withErrors(['email' => __($status)]);
77
+
? back()->with(['status' => __($status)])
78
+
: back()->withErrors(['email' => __($status)]);
79
79
})->middleware('guest')->name('password.email');
80
80
81
81
Before moving on, let's examine this route in more detail. First, the request's `email` attribute is validated. Next, we will use Laravel's built-in "password broker" (via the `Password` facade) to send a password reset link to the user. The password broker will take care of retrieving the user by the given field (in this case, the email address) and sending the user a password reset link via Laravel's built-in [notification system](/docs/{{version}}/notifications).
@@ -137,8 +137,8 @@ Of course, we need to define a route to actually handle the password reset form
Before moving on, let's examine this route in more detail. First, the request's `token`, `email`, and `password` attributes are validated. Next, we will use Laravel's built-in "password broker" (via the `Password` facade) to validate the password reset request credentials.
Copy file name to clipboardExpand all lines: pennant.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -199,8 +199,8 @@ class PodcastController
199
199
public function index(Request $request): Response
200
200
{
201
201
return Feature::active('new-api')
202
-
? $this->resolveNewApiResponse($request)
203
-
: $this->resolveLegacyApiResponse($request);
202
+
? $this->resolveNewApiResponse($request)
203
+
: $this->resolveLegacyApiResponse($request);
204
204
}
205
205
206
206
// ...
@@ -211,8 +211,8 @@ Although features are checked against the currently authenticated user by defaul
211
211
212
212
```php
213
213
return Feature::for($user)->active('new-api')
214
-
? $this->resolveNewApiResponse($request)
215
-
: $this->resolveLegacyApiResponse($request);
214
+
? $this->resolveNewApiResponse($request)
215
+
: $this->resolveLegacyApiResponse($request);
216
216
```
217
217
218
218
Pennant also offers some additional convenience methods that may prove useful when determining if a feature is active or not:
@@ -260,8 +260,8 @@ class PodcastController
260
260
public function index(Request $request): Response
261
261
{
262
262
return Feature::active(NewApi::class)
263
-
? $this->resolveNewApiResponse($request)
264
-
: $this->resolveLegacyApiResponse($request);
263
+
? $this->resolveNewApiResponse($request)
264
+
: $this->resolveLegacyApiResponse($request);
265
265
}
266
266
267
267
// ...
@@ -509,8 +509,8 @@ As discussed, features are typically checked against the currently authenticated
509
509
510
510
```php
511
511
return Feature::for($user)->active('new-api')
512
-
? $this->resolveNewApiResponse($request)
513
-
: $this->resolveLegacyApiResponse($request);
512
+
? $this->resolveNewApiResponse($request)
513
+
: $this->resolveLegacyApiResponse($request);
514
514
```
515
515
516
516
Of course, feature scopes are not limited to "users". Imagine you have built a new billing experience that you are rolling out to entire teams rather than individual users. Perhaps you would like the oldest teams to have a slower rollout than the newer teams. Your feature resolution closure might look something like the following:
Copy file name to clipboardExpand all lines: routing.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -791,8 +791,8 @@ Since rate limiter callbacks receive the incoming HTTP request instance, you may
791
791
792
792
RateLimiter::for('uploads', function (Request $request) {
793
793
return $request->user()->vipCustomer()
794
-
? Limit::none()
795
-
: Limit::perMinute(100);
794
+
? Limit::none()
795
+
: Limit::perMinute(100);
796
796
});
797
797
798
798
<aname="segmenting-rate-limits"></a>
@@ -802,16 +802,16 @@ Sometimes you may wish to segment rate limits by some arbitrary value. For examp
802
802
803
803
RateLimiter::for('uploads', function (Request $request) {
804
804
return $request->user()->vipCustomer()
805
-
? Limit::none()
806
-
: Limit::perMinute(100)->by($request->ip());
805
+
? Limit::none()
806
+
: Limit::perMinute(100)->by($request->ip());
807
807
});
808
808
809
809
To illustrate this feature using another example, we can limit access to the route to 100 times per minute per authenticated user ID or 10 times per minute per IP address for guests:
810
810
811
811
RateLimiter::for('uploads', function (Request $request) {
0 commit comments