Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Enum DB Columns, PHP Enums and Foreign Keys

Premium
5 min read

In this lesson, we will discuss different kinds of Enums. There are two ways to use Enums: as a database column or with PHP native Enums.


Option 1: Database Column

First, let's look at the database enum column. You can create it by defining the enum() column in the migrations and providing the values as a second column in an array.

Schema::create('tickets', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->enum('status', ['open', 'closed'])->default('open');
$table->timestamps();
});

But with database fields come some issues. First, where should these values be saved in the code? For example, when creating or editing a ticket, a user might need to be able to select a status. You may need to filter by ticket status somewhere.

One way to deal with this issue could be to define statuses as...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…