Laravel 11 introduced new Artisan commands. Let's look at the make:class
command in this post.
As with every Artisan command, you can pass the file name to create or leave empty, and Laravel will ask.
Here is how the generated class looks like:
app/Actions/CreateUserAction.php:
namespace App\Actions; class CreateUserAction{ /** * Create a new class instance. */ public function __construct() { // }}
By passing --invokable
, the generated class will have the __invoke()
method.
app/Actions/DeleteUserAction.php:
namespace App\Actions; class DeleteUserAction{ /** * Create a new class instance. */ public function __construct() { // } /** * Invoke the class instance. */ public function __invoke(): void { }}
As with every generated file, the class also has stubs so that you can modify them to your needs. After publishing the subs, you may change these defaults:
stubs/class.stub:
<?php namespace {{ namespace }}; class {{ class }}{ /** * Create a new class instance. */ public function __construct() { // }}
stubs/class.invokable.stub:
<?php namespace {{ namespace }}; class {{ class }}{ /** * Create a new class instance. */ public function __construct() { // } /** * Invoke the class instance. */ public function __invoke(): void { }}
The make:class
Artisan command has additional options, which you can check by adding the --help
option.
No comments or questions yet...