Support the ongoing development of Laravel.io →
posted 10 years ago
Database
Last updated 2 years ago.
0

As of now Laravel Schema Builder does not support SET datatype for columns. So, here is an alternative solution until someone add those code to Laravel.

Step 1: Create the table, use ENUM instead of SET.

Schema::create('schools', function($table)
{
    $table->increments('id');
    $table->char('id_number', 6);
    $table->string('school_name');
    $table->enum('level', array('Preschool', 'Kindergarten', 'Primary', 'Secondary'))->index();	// *** fix this
    $table->string('phone');
    $table->string('email');
    $table->string('location');
    $table->smallInteger('city')->unsigned()->index();
    $table->smallInteger('country')->unsigned()->index();
    $table->smallInteger('head_teacher')->unsigned()->index();
    $table->smallInteger('director')->unsigned()->index();
    $table->smallInteger('created_by')->unsigned();
    $table->smallInteger('modified_by')->unsigned();
    $table->timestamps();
});

Now change ENUM to SET.

$table_prefix = DB::getTablePrefix();
DB::statement("ALTER TABLE `" . $table_prefix . "schools` CHANGE `level` `level` SET('Preschool','Kindergarten','Primary','Secondary');");

If you have a better solution, then please let me know.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Debiprasad debiprasad Joined 18 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.