Laravel 11: New Artisan "make:class" Command

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.

make class command

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.

make class command invokable

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.

make class command help

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 68 courses (1183 lessons, total 43 h 18 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses