Hello Artisan,
In this Laravel enum tutorial, I will show you how to use enum data type in Laravel migration schema. Sometimes we need to create a field that contains many types like pending, accepted, rejected, etc. In this type of situation, we can use the enum data type in Laravel migration.
So if you don't know how to use this Laravel enum in database schema, then this enum in the Laravel 8 tutorial is for you. I will simply show you an example of how to use enum data type in your Laravel migrations. Show the below example of enum data type in migration:
database/migrations
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOrdersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('orders', function (Blueprint $table) {
$table->id();
$table->enum('status',['pending','cancelled','completed'])->default('pending');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('orders');
}
}
Recommended : The Substitution of Laravel Chunk to Process Big Data Example
Hope this Laravel enum tutorial will help you.
#laravel #laravel-8x #laravel-migrations