'string', 'template' => 'string', ]; /** * The fillable properties. * * @var string[] */ protected $fillable = ['name', 'template']; /** * The validation rules. * * @var string[] */ public $rules = [ 'name' => 'required', 'template' => 'required', ]; /** * Overrides the models boot method. */ public static function boot() { parent::boot(); self::saving(function ($template) { $template->slug = Str::slug($template->name); }); } /** * Finds a template by the slug. * * @param \Illuminate\Database\Query\Builder $query * @param string $slug * * @return \Illuminate\Database\Query\Builder */ public function scopeForSlug($query, $slug) { return $query->where('slug', $slug); } }