Ad
Laravel Set State Column
I am wanting to add a new column to my film table called status
which has two options active
or inactive
i am wanting to set all the current films in the DB to be active by default.
My first thought is to create a library file with the states set as constants incase i ever decide to add more down the line. e.g
const active = 1;
const inactive = 2;
can i then just pass the constant in as a default in the new column?
migration file
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('films', function (Blueprint $table) {
$table->string('status')->default(\App\Library\Status::active);
});
}
some help would be great
Ad
Answer
Set datatype as an enum
and set a value as active
and deactive
with default value active
it'll automatically set active
you don't need to pass it by const.
$table->enum('status',['active','deactive'])->default('active');
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad