Reputation: 25
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.
Upvotes: 0
Views: 277
Reputation: 7824
Add this to your model
protected $attributes = [
'somecolumn'
];
public function getSomecolumnAttribute() {
return str_slug($this->attributes['name'],'-');
}
Upvotes: 1
Reputation: 4040
$title = str_slug("Laravel 5 Framework", "-");
//output: laravel-5-framework follow url for more helpers https://laravel.com/docs/5.0/helpers
Upvotes: 0