0

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');
        });
    }

Image in checking if enum data type created, and check if all tables are created

nyx97
  • 179
  • 1
  • 13
  • Does this answer your question? [Laravel 5.3 Schema::create ENUM field is VARCHAR](https://stackoverflow.com/questions/40384827/laravel-5-3-schemacreate-enum-field-is-varchar) – miken32 Nov 18 '19 at 03:51
  • @miken32 how can I implement it? the answer is pretty straightforward, would you like to explain a little bit more about it? the link you provide is related to my problem but the OP does not explain how he arrive to the answer – nyx97 Nov 18 '19 at 04:16
  • No idea; if Laravel/Doctrine won't do it you can just use raw SQL query in your migration. – miken32 Nov 18 '19 at 04:21

2 Answers2

4

You can simply do:

$table -> enum('tableStatus',['VACANT','OCCUPIED','RESERVED','FOR CLEANING'])->default('VACANT');
Anil Stha
  • 515
  • 7
  • 12
2
$table->enum('tableStatus',['Vacant', 'Reserved', 'Occupied', 'For Cleaning']);

First one will be default

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103