I have to fields make,model and variant for a car leasing plugin i have written. i want the slug to have the format make_model_variant. how can i combine the 3 fields to generate thd blog
thanks
This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I have to fields make,model and variant for a car leasing plugin i have written. i want the slug to have the format make_model_variant. how can i combine the 3 fields to generate thd blog
thanks
Easiest way to do this is in the beforeSave() method on your model.
class Car extends Model {
use \October\Rain\Database\Traits\Sluggable;
/**
* @var array Generate slugs for these attributes.
*/
protected $slugs = ['slug' => 'name'];
public function beforeSave()
{
// Autogenerate name
if (empty($this->name)) {
$this->name = $this->make . ' ' . $this->model . ' ' . $this->variant;
}
// Force creation of slug
if (empty($this->slug)) {
unset($this->slug);
$this->setSluggedValue('slug', 'name');
}
}
}
as an example that assumes you have a name property on the Car model and then generates a name out of the desired properties and generates a slug based on the name respecting potential duplicates within the database.
1-4 of 4