Yes, you can set up a mutator in your model to handle this. Here's an example:
class YourModel extends Model
{
// ...
public function getYourColumnAttribute($value)
{
return $value ? 'Yes' : 'No';
}
public function setYourColumnAttribute($value)
{
$this->attributes['your_column'] = $value ? 1 : 0;
}
}
This mutator will automatically convert the value of your column to 'Yes' or 'No' when you retrieve it from the model, and it will convert 'Yes' or 'No' back to 1 or 0 when you set the value on the model. You can then use the column in your code as a boolean value (i.e. if ($model->your_column) { ... }).
@tykus Thank you, I still have a problem because I can't use a function when reading from the database, I need to get the value from the database as Yes or No without calling a function. Can't explain why here, too complicated. But thank you
Create an accessor that returns textual version as a differently named attribute.
eg, if your column was called 'account_suspended', you could create accessor called accountSuspendedText which returns yes/no and then use that in your view, but the existing column name accountSuspended in your back-end code