'How can I create laravel migration with enum type column?
I am trying to create enum column in laravel migration. Upon executing the query it does create column in the table but checking in postgresql for created enum types, it shows theres none. Does anyone ever experience this?
I am using laravel 5.4, php 7 and vagrant
Migration code
public function up()
{
Schema::create('restaurant_tables', function(Blueprint $table){
$table->increments('_id');
$table->string('tableNo', 100);
$table->json('spatialLocation');
$table->enum('tableStatus' , array('Occupied', 'Reserved', 'Vacant', 'For Cleaning'))->default('Vacant');
$table->integer('numberOfCustomers');
$table->integer('seatLimit');
$table->string('tableDimension', 100);
$table->enum('tableType', ['4x4','16x4','8x4']);
$table->bigInteger('chairID');
});
Schema::table('restaurant_tables', function(Blueprint $table){
$table->foreign('chairID')->references('_id')->on('restaurant_chairs');
});
}
Solution 1:[1]
You can simply do:
$table -> enum('tableStatus',['VACANT','OCCUPIED','RESERVED','FOR CLEANING'])->default('VACANT');
Solution 2:[2]
$table->enum('tableStatus',['Vacant', 'Reserved', 'Occupied', 'For Cleaning']);
First one will be default
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Suraj Rao |

