Skip to content

Commit 7f37ebd

Browse files
authored
use promoted properties (#8536)
using promoted properties makes the docs more succinct. I did not switch to promoted properties when the properties were not explicitly defined in the code already.
1 parent 399ace7 commit 7f37ebd

File tree

12 files changed

+49
-180
lines changed

12 files changed

+49
-180
lines changed

blade.md

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -735,28 +735,13 @@ You should define all of the component's data attributes in its class constructo
735735

736736
class Alert extends Component
737737
{
738-
/**
739-
* The alert type.
740-
*
741-
* @var string
742-
*/
743-
public $type;
744-
745-
/**
746-
* The alert message.
747-
*
748-
* @var string
749-
*/
750-
public $message;
751-
752738
/**
753739
* Create the component instance.
754740
*/
755-
public function __construct(string $type, string $message)
756-
{
757-
$this->type = $type;
758-
$this->message = $message;
759-
}
741+
public function __construct(
742+
public string $type,
743+
public string $message,
744+
) {}
760745

761746
/**
762747
* Get the view / contents that represent the component.

broadcasting.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -375,20 +375,12 @@ The `ShouldBroadcast` interface requires you to implement a single method: `broa
375375
{
376376
use SerializesModels;
377377

378-
/**
379-
* The user that created the server.
380-
*
381-
* @var \App\Models\User
382-
*/
383-
public $user;
384-
385378
/**
386379
* Create a new event instance.
387380
*/
388-
public function __construct(User $user)
389-
{
390-
$this->user = $user;
391-
}
381+
public function __construct(
382+
public User $user,
383+
) {}
392384

393385
/**
394386
* Get the channels the event should broadcast on.

collections.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,18 +1655,12 @@ The `pipeInto` method creates a new instance of the given class and passes the c
16551655

16561656
class ResourceCollection
16571657
{
1658-
/**
1659-
* The Collection instance.
1660-
*/
1661-
public $collection;
1662-
16631658
/**
16641659
* Create a new ResourceCollection instance.
16651660
*/
1666-
public function __construct(Collection $collection)
1667-
{
1668-
$this->collection = $collection;
1669-
}
1661+
public function __construct(
1662+
public Collection $collection,
1663+
) {}
16701664
}
16711665

16721666
$collection = collect([1, 2, 3]);

container.md

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,12 @@ Let's look at a simple example:
3636

3737
class UserController extends Controller
3838
{
39-
/**
40-
* The user repository implementation.
41-
*
42-
* @var UserRepository
43-
*/
44-
protected $users;
45-
4639
/**
4740
* Create a new controller instance.
4841
*/
49-
public function __construct(UserRepository $users)
50-
{
51-
$this->users = $users;
52-
}
42+
public function __construct(
43+
protected UserRepository $users,
44+
) {}
5345

5446
/**
5547
* Show the profile for the given user.
@@ -395,20 +387,12 @@ For example, you may type-hint a repository defined by your application in a con
395387

396388
class UserController extends Controller
397389
{
398-
/**
399-
* The user repository instance.
400-
*
401-
* @var \App\Repositories\UserRepository
402-
*/
403-
protected $users;
404-
405390
/**
406391
* Create a new controller instance.
407392
*/
408-
public function __construct(UserRepository $users)
409-
{
410-
$this->users = $users;
411-
}
393+
public function __construct(
394+
protected UserRepository $users,
395+
) {}
412396

413397
/**
414398
* Show the user with the given ID.

contracts.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,12 @@ For example, take a look at this event listener:
4848

4949
class CacheOrderInformation
5050
{
51-
/**
52-
* The Redis factory implementation.
53-
*
54-
* @var \Illuminate\Contracts\Redis\Factory
55-
*/
56-
protected $redis;
57-
5851
/**
5952
* Create a new event handler instance.
6053
*/
61-
public function __construct(Factory $redis)
62-
{
63-
$this->redis = $redis;
64-
}
54+
public function __construct(
55+
protected Factory $redis,
56+
) {}
6557

6658
/**
6759
* Handle the event.

controllers.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -465,18 +465,12 @@ The Laravel [service container](/docs/{{version}}/container) is used to resolve
465465

466466
class UserController extends Controller
467467
{
468-
/**
469-
* The user repository instance.
470-
*/
471-
protected $users;
472-
473468
/**
474469
* Create a new controller instance.
475470
*/
476-
public function __construct(UserRepository $users)
477-
{
478-
$this->users = $users;
479-
}
471+
public function __construct(
472+
protected UserRepository $users,
473+
) {}
480474
}
481475

482476
<a name="method-injection"></a>

eloquent-mutators.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -654,20 +654,12 @@ A classic example of an inbound only cast is a "hashing" cast. For example, we m
654654

655655
class Hash implements CastsInboundAttributes
656656
{
657-
/**
658-
* The hashing algorithm.
659-
*
660-
* @var string
661-
*/
662-
protected $algorithm;
663-
664657
/**
665658
* Create a new cast class instance.
666659
*/
667-
public function __construct(string $algorithm = null)
668-
{
669-
$this->algorithm = $algorithm;
670-
}
660+
public function __construct(
661+
protected string $algorithm = null,
662+
) {}
671663

672664
/**
673665
* Prepare the given value for storage.

events.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,20 +200,12 @@ An event class is essentially a data container which holds the information relat
200200
{
201201
use Dispatchable, InteractsWithSockets, SerializesModels;
202202

203-
/**
204-
* The order instance.
205-
*
206-
* @var \App\Models\Order
207-
*/
208-
public $order;
209-
210203
/**
211204
* Create a new event instance.
212205
*/
213-
public function __construct(Order $order)
214-
{
215-
$this->order = $order;
216-
}
206+
public function __construct(
207+
public Order $order,
208+
) {}
217209
}
218210

219211
As you can see, this event class contains no logic. It is a container for the `App\Models\Order` instance that was purchased. The `SerializesModels` trait used by the event will gracefully serialize any Eloquent models if the event object is serialized using PHP's `serialize` function, such as when utilizing [queued listeners](#queued-event-listeners).

horizon.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,20 +304,12 @@ Horizon allows you to assign “tags” to jobs, including mailables, broadcast
304304
{
305305
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
306306

307-
/**
308-
* The video instance.
309-
*
310-
* @var \App\Models\Video
311-
*/
312-
public $video;
313-
314307
/**
315308
* Create a new job instance.
316309
*/
317-
public function __construct(Video $video)
318-
{
319-
$this->video = $video;
320-
}
310+
public function __construct(
311+
public Video $video,
312+
) {}
321313

322314
/**
323315
* Execute the job.

mail.md

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,12 @@ Typically, you will want to pass some data to your view that you can utilize whe
281281
{
282282
use Queueable, SerializesModels;
283283

284-
/**
285-
* The order instance.
286-
*
287-
* @var \App\Models\Order
288-
*/
289-
public $order;
290-
291284
/**
292285
* Create a new message instance.
293286
*/
294-
public function __construct(Order $order)
295-
{
296-
$this->order = $order;
297-
}
287+
public function __construct(
288+
public Order $order,
289+
) {}
298290

299291
/**
300292
* Get the message content definition.
@@ -332,20 +324,12 @@ If you would like to customize the format of your email's data before it is sent
332324
{
333325
use Queueable, SerializesModels;
334326

335-
/**
336-
* The order instance.
337-
*
338-
* @var \App\Models\Order
339-
*/
340-
protected $order;
341-
342327
/**
343328
* Create a new message instance.
344329
*/
345-
public function __construct(Order $order)
346-
{
347-
$this->order = $order;
348-
}
330+
public function __construct(
331+
protected Order $order,
332+
) {}
349333

350334
/**
351335
* Get the message content definition.
@@ -1059,21 +1043,13 @@ Laravel includes a variety of mail transports; however, you may wish to write yo
10591043

10601044
class MailchimpTransport extends AbstractTransport
10611045
{
1062-
/**
1063-
* The Mailchimp API client.
1064-
*
1065-
* @var \MailchimpTransactional\ApiClient
1066-
*/
1067-
protected $client;
1068-
10691046
/**
10701047
* Create a new Mailchimp transport instance.
10711048
*/
1072-
public function __construct(ApiClient $client)
1073-
{
1049+
public function __construct(
1050+
protected ApiClient $client,
1051+
) {
10741052
parent::__construct();
1075-
1076-
$this->client = $client;
10771053
}
10781054

10791055
/**

0 commit comments

Comments
 (0)