Laravel 11: New Artisan "make:enum" Command

Laravel 11 introduced new Artisan commands. Let's look at the make:enum command in this post.

As with every Artisan command, you can pass the file name to create or leave empty, and Laravel will ask. Additionally, you will be asked which type you would like the enum to be.

make enum command

Here is how the generated enum backed as string looks like:

app/Enums/OrderStatus.php:

namespace App\Enums;
 
enum OrderStatus: string
{
//
}

Also, you can pass the backed type with --string or --int options.

make enum command backed string

namespace App\Enums;
 
enum PostStatus: string
{
//
}

As with every generated file, the enum also has stubs so that you can modify them to your needs. After publishing the subs, you can customize these defaults:

stubs/enum.stub

<?php
 
namespace {{ namespace }};
 
enum {{ class }}
{
//
}

stubs/enum.backed.stub

<?php
 
namespace {{ namespace }};
 
enum {{ class }}: {{ type }}
{
//
}

The make:enum Artisan command has additional options, which you can check by adding the --help option.

make enum 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:
  • 59 courses (1056 lessons, total 44 h 09 min)
  • 78 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent Premium Tutorials