Skip to content

Commit 490a498

Browse files
authored
remove arbitrary chaining alignment (#10166)
use a single indent for chains on a new line, rather than trying to align it with some arbitrary pattern in the first line. this arbitrary alignment very easily gets out of sync as changes occur to the code, and often times the adjustments are not made to the chained alignment. the single indent alignment does not suffer this problem. this is to bring us in line with laravel/framework#53835 and laravel/framework#53748 this commit only contains whitespace changes. if accepted, I will make these adjustments to the remaining docs pages.
1 parent 6fe1c61 commit 490a498

7 files changed

+413
-413
lines changed

billing.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,8 @@ The amount of time a customer has to pay their invoice before their subscription
842842
If you would like to set a specific [quantity](https://stripe.com/docs/billing/subscriptions/quantities) for the price when creating the subscription, you should invoke the `quantity` method on the subscription builder before creating the subscription:
843843

844844
$user->newSubscription('default', 'price_monthly')
845-
->quantity(5)
846-
->create($paymentMethod);
845+
->quantity(5)
846+
->create($paymentMethod);
847847

848848
<a name="additional-details"></a>
849849
#### Additional Details
@@ -862,14 +862,14 @@ If you would like to specify additional [customer](https://stripe.com/docs/api/c
862862
If you would like to apply a coupon when creating the subscription, you may use the `withCoupon` method:
863863

864864
$user->newSubscription('default', 'price_monthly')
865-
->withCoupon('code')
866-
->create($paymentMethod);
865+
->withCoupon('code')
866+
->create($paymentMethod);
867867

868868
Or, if you would like to apply a [Stripe promotion code](https://stripe.com/docs/billing/subscriptions/discounts/codes), you may use the `withPromotionCode` method:
869869

870870
$user->newSubscription('default', 'price_monthly')
871-
->withPromotionCode('promo_code_id')
872-
->create($paymentMethod);
871+
->withPromotionCode('promo_code_id')
872+
->create($paymentMethod);
873873

874874
The given promotion code ID should be the Stripe API ID assigned to the promotion code and not the customer facing promotion code. If you need to find a promotion code ID based on a given customer facing promotion code, you may use the `findPromotionCode` method:
875875

@@ -1104,8 +1104,8 @@ If the customer is on trial, the trial period will be maintained. Additionally,
11041104
If you would like to swap prices and cancel any trial period the customer is currently on, you may invoke the `skipTrial` method:
11051105

11061106
$user->subscription('default')
1107-
->skipTrial()
1108-
->swap('price_yearly');
1107+
->skipTrial()
1108+
->swap('price_yearly');
11091109

11101110
If you would like to swap prices and immediately invoice the customer instead of waiting for their next billing cycle, you may use the `swapAndInvoice` method:
11111111

@@ -1237,8 +1237,8 @@ If you want to swap a single price on a subscription, you may do so using the `s
12371237
$user = User::find(1);
12381238

12391239
$user->subscription('default')
1240-
->findItemOrFail('price_basic')
1241-
->swap('price_pro');
1240+
->findItemOrFail('price_basic')
1241+
->swap('price_pro');
12421242

12431243
<a name="proration"></a>
12441244
#### Proration
@@ -1329,9 +1329,9 @@ To start using usage billing, you will first need to create a new product in you
13291329
You may also start a metered subscription via [Stripe Checkout](#checkout):
13301330

13311331
$checkout = Auth::user()
1332-
->newSubscription('default', [])
1333-
->meteredPrice('price_metered')
1334-
->checkout();
1332+
->newSubscription('default', [])
1333+
->meteredPrice('price_metered')
1334+
->checkout();
13351335

13361336
return view('your-checkout-view', [
13371337
'checkout' => $checkout,
@@ -1441,8 +1441,8 @@ By default, the billing cycle anchor is the date the subscription was created or
14411441
$anchor = Carbon::parse('first day of next month');
14421442

14431443
$request->user()->newSubscription('default', 'price_monthly')
1444-
->anchorBillingCycleOn($anchor->startOfDay())
1445-
->create($request->paymentMethodId);
1444+
->anchorBillingCycleOn($anchor->startOfDay())
1445+
->create($request->paymentMethodId);
14461446

14471447
// ...
14481448
});
@@ -1507,8 +1507,8 @@ If you would like to offer trial periods to your customers while still collectin
15071507

15081508
Route::post('/user/subscribe', function (Request $request) {
15091509
$request->user()->newSubscription('default', 'price_monthly')
1510-
->trialDays(10)
1511-
->create($request->paymentMethodId);
1510+
->trialDays(10)
1511+
->create($request->paymentMethodId);
15121512

15131513
// ...
15141514
});
@@ -1523,8 +1523,8 @@ The `trialUntil` method allows you to provide a `DateTime` instance that specifi
15231523
use Carbon\Carbon;
15241524

15251525
$user->newSubscription('default', 'price_monthly')
1526-
->trialUntil(Carbon::now()->addDays(10))
1527-
->create($paymentMethod);
1526+
->trialUntil(Carbon::now()->addDays(10))
1527+
->create($paymentMethod);
15281528

15291529
You may determine if a user is within their trial period using either the `onTrial` method of the user instance or the `onTrial` method of the subscription instance. The two examples below are equivalent:
15301530

@@ -2131,7 +2131,7 @@ First, you could redirect your customer to the dedicated payment confirmation pa
21312131

21322132
try {
21332133
$subscription = $user->newSubscription('default', 'price_monthly')
2134-
->create($paymentMethod);
2134+
->create($paymentMethod);
21352135
} catch (IncompletePayment $exception) {
21362136
return redirect()->route(
21372137
'cashier.payment',

eloquent-factories.md

+85-85
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,12 @@ Sometimes you may wish to alternate the value of a given model attribute for eac
267267
use Illuminate\Database\Eloquent\Factories\Sequence;
268268

269269
$users = User::factory()
270-
->count(10)
271-
->state(new Sequence(
272-
['admin' => 'Y'],
273-
['admin' => 'N'],
274-
))
275-
->create();
270+
->count(10)
271+
->state(new Sequence(
272+
['admin' => 'Y'],
273+
['admin' => 'N'],
274+
))
275+
->create();
276276

277277
In this example, five users will be created with an `admin` value of `Y` and five users will be created with an `admin` value of `N`.
278278

@@ -281,28 +281,28 @@ If necessary, you may include a closure as a sequence value. The closure will be
281281
use Illuminate\Database\Eloquent\Factories\Sequence;
282282

283283
$users = User::factory()
284-
->count(10)
285-
->state(new Sequence(
286-
fn (Sequence $sequence) => ['role' => UserRoles::all()->random()],
287-
))
288-
->create();
284+
->count(10)
285+
->state(new Sequence(
286+
fn (Sequence $sequence) => ['role' => UserRoles::all()->random()],
287+
))
288+
->create();
289289

290290
Within a sequence closure, you may access the `$index` or `$count` properties on the sequence instance that is injected into the closure. The `$index` property contains the number of iterations through the sequence that have occurred thus far, while the `$count` property contains the total number of times the sequence will be invoked:
291291

292292
$users = User::factory()
293-
->count(10)
294-
->sequence(fn (Sequence $sequence) => ['name' => 'Name '.$sequence->index])
295-
->create();
293+
->count(10)
294+
->sequence(fn (Sequence $sequence) => ['name' => 'Name '.$sequence->index])
295+
->create();
296296

297297
For convenience, sequences may also be applied using the `sequence` method, which simply invokes the `state` method internally. The `sequence` method accepts a closure or arrays of sequenced attributes:
298298

299299
$users = User::factory()
300-
->count(2)
301-
->sequence(
302-
['name' => 'First User'],
303-
['name' => 'Second User'],
304-
)
305-
->create();
300+
->count(2)
301+
->sequence(
302+
['name' => 'First User'],
303+
['name' => 'Second User'],
304+
)
305+
->create();
306306

307307
<a name="factory-relationships"></a>
308308
## Factory Relationships
@@ -316,51 +316,51 @@ Next, let's explore building Eloquent model relationships using Laravel's fluent
316316
use App\Models\User;
317317

318318
$user = User::factory()
319-
->has(Post::factory()->count(3))
320-
->create();
319+
->has(Post::factory()->count(3))
320+
->create();
321321

322322
By convention, when passing a `Post` model to the `has` method, Laravel will assume that the `User` model must have a `posts` method that defines the relationship. If necessary, you may explicitly specify the name of the relationship that you would like to manipulate:
323323

324324
$user = User::factory()
325-
->has(Post::factory()->count(3), 'posts')
326-
->create();
325+
->has(Post::factory()->count(3), 'posts')
326+
->create();
327327

328328
Of course, you may perform state manipulations on the related models. In addition, you may pass a closure based state transformation if your state change requires access to the parent model:
329329

330330
$user = User::factory()
331-
->has(
332-
Post::factory()
333-
->count(3)
334-
->state(function (array $attributes, User $user) {
335-
return ['user_type' => $user->type];
336-
})
337-
)
338-
->create();
331+
->has(
332+
Post::factory()
333+
->count(3)
334+
->state(function (array $attributes, User $user) {
335+
return ['user_type' => $user->type];
336+
})
337+
)
338+
->create();
339339

340340
<a name="has-many-relationships-using-magic-methods"></a>
341341
#### Using Magic Methods
342342

343343
For convenience, you may use Laravel's magic factory relationship methods to build relationships. For example, the following example will use convention to determine that the related models should be created via a `posts` relationship method on the `User` model:
344344

345345
$user = User::factory()
346-
->hasPosts(3)
347-
->create();
346+
->hasPosts(3)
347+
->create();
348348

349349
When using magic methods to create factory relationships, you may pass an array of attributes to override on the related models:
350350

351351
$user = User::factory()
352-
->hasPosts(3, [
353-
'published' => false,
354-
])
355-
->create();
352+
->hasPosts(3, [
353+
'published' => false,
354+
])
355+
->create();
356356

357357
You may provide a closure based state transformation if your state change requires access to the parent model:
358358

359359
$user = User::factory()
360-
->hasPosts(3, function (array $attributes, User $user) {
361-
return ['user_type' => $user->type];
362-
})
363-
->create();
360+
->hasPosts(3, function (array $attributes, User $user) {
361+
return ['user_type' => $user->type];
362+
})
363+
->create();
364364

365365
<a name="belongs-to-relationships"></a>
366366
### Belongs To Relationships
@@ -371,32 +371,32 @@ Now that we have explored how to build "has many" relationships using factories,
371371
use App\Models\User;
372372

373373
$posts = Post::factory()
374-
->count(3)
375-
->for(User::factory()->state([
376-
'name' => 'Jessica Archer',
377-
]))
378-
->create();
374+
->count(3)
375+
->for(User::factory()->state([
376+
'name' => 'Jessica Archer',
377+
]))
378+
->create();
379379

380380
If you already have a parent model instance that should be associated with the models you are creating, you may pass the model instance to the `for` method:
381381

382382
$user = User::factory()->create();
383383

384384
$posts = Post::factory()
385-
->count(3)
386-
->for($user)
387-
->create();
385+
->count(3)
386+
->for($user)
387+
->create();
388388

389389
<a name="belongs-to-relationships-using-magic-methods"></a>
390390
#### Using Magic Methods
391391

392392
For convenience, you may use Laravel's magic factory relationship methods to define "belongs to" relationships. For example, the following example will use convention to determine that the three posts should belong to the `user` relationship on the `Post` model:
393393

394394
$posts = Post::factory()
395-
->count(3)
396-
->forUser([
397-
'name' => 'Jessica Archer',
398-
])
399-
->create();
395+
->count(3)
396+
->forUser([
397+
'name' => 'Jessica Archer',
398+
])
399+
->create();
400400

401401
<a name="many-to-many-relationships"></a>
402402
### Many to Many Relationships
@@ -407,8 +407,8 @@ Like [has many relationships](#has-many-relationships), "many to many" relations
407407
use App\Models\User;
408408

409409
$user = User::factory()
410-
->has(Role::factory()->count(3))
411-
->create();
410+
->has(Role::factory()->count(3))
411+
->create();
412412

413413
<a name="pivot-table-attributes"></a>
414414
#### Pivot Table Attributes
@@ -419,44 +419,44 @@ If you need to define attributes that should be set on the pivot / intermediate
419419
use App\Models\User;
420420

421421
$user = User::factory()
422-
->hasAttached(
423-
Role::factory()->count(3),
424-
['active' => true]
425-
)
426-
->create();
422+
->hasAttached(
423+
Role::factory()->count(3),
424+
['active' => true]
425+
)
426+
->create();
427427

428428
You may provide a closure based state transformation if your state change requires access to the related model:
429429

430430
$user = User::factory()
431-
->hasAttached(
432-
Role::factory()
433-
->count(3)
434-
->state(function (array $attributes, User $user) {
435-
return ['name' => $user->name.' Role'];
436-
}),
437-
['active' => true]
438-
)
439-
->create();
431+
->hasAttached(
432+
Role::factory()
433+
->count(3)
434+
->state(function (array $attributes, User $user) {
435+
return ['name' => $user->name.' Role'];
436+
}),
437+
['active' => true]
438+
)
439+
->create();
440440

441441
If you already have model instances that you would like to be attached to the models you are creating, you may pass the model instances to the `hasAttached` method. In this example, the same three roles will be attached to all three users:
442442

443443
$roles = Role::factory()->count(3)->create();
444444

445445
$user = User::factory()
446-
->count(3)
447-
->hasAttached($roles, ['active' => true])
448-
->create();
446+
->count(3)
447+
->hasAttached($roles, ['active' => true])
448+
->create();
449449

450450
<a name="many-to-many-relationships-using-magic-methods"></a>
451451
#### Using Magic Methods
452452

453453
For convenience, you may use Laravel's magic factory relationship methods to define many to many relationships. For example, the following example will use convention to determine that the related models should be created via a `roles` relationship method on the `User` model:
454454

455455
$user = User::factory()
456-
->hasRoles(1, [
457-
'name' => 'Editor'
458-
])
459-
->create();
456+
->hasRoles(1, [
457+
'name' => 'Editor'
458+
])
459+
->create();
460460

461461
<a name="polymorphic-relationships"></a>
462462
### Polymorphic Relationships
@@ -485,17 +485,17 @@ Polymorphic "many to many" (`morphToMany` / `morphedByMany`) relationships may b
485485
use App\Models\Video;
486486

487487
$videos = Video::factory()
488-
->hasAttached(
489-
Tag::factory()->count(3),
490-
['public' => true]
491-
)
492-
->create();
488+
->hasAttached(
489+
Tag::factory()->count(3),
490+
['public' => true]
491+
)
492+
->create();
493493

494494
Of course, the magic `has` method may also be used to create polymorphic "many to many" relationships:
495495

496496
$videos = Video::factory()
497-
->hasTags(3, ['public' => true])
498-
->create();
497+
->hasTags(3, ['public' => true])
498+
->create();
499499

500500
<a name="defining-relationships-within-factories"></a>
501501
### Defining Relationships Within Factories

0 commit comments

Comments
 (0)