Boolean or Int - a solution that feels right (Laravel 10 & Mysql)

Define the column as Boolean in the migration file

$table->boolean('active')->default(0);

Cast the column in the Model file

protected  $casts  =  [
    'active'  =>  'boolean',
];

Check the value inside View to display component state accordingly

@if (  $user->active  )

Retrieve the value of Boolean control (submitted by a form) inside Controller. This could be coming from a Radio or Checkbox or Select input on a View:

'active'  =>  $request->boolean('active'),
comments powered by Disqus