I have a Location
Model and Migration. Here I have name
. Now I want to add an extra column (calculated), that will be name
column with some replacement of special characters, and spaces to -
. I will write that replace function by myself. I can't find a way of introducing calculated columns. Thanks.
$title = str_slug("Laravel 5 Framework", "-");
//output: laravel-5-framework follow url for more helpers https://laravel.com/docs/5.0/helpers
Add this to your model
protected $attributes = [
'somecolumn'
];
public function getSomecolumnAttribute() {
return str_slug($this->attributes['name'],'-');
}