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...