ldc-legaulois/app/Models/SubRange.php
2022-02-10 16:14:58 +01:00

43 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
class SubRange extends Model
{
use HasFactory;
protected $attributes = [
'back_link_url' => '',
'back_link_text' => ''
];
protected $fillable = [
'name', 'picture_alt',
'back_link_url', 'back_link_text',
'back_link_display', 'title',
'subtitle', 'content'
];
protected static function booted()
{
static::creating(function (SubRange $subRange) {
$subRange->title = clean($subRange->title);
$subRange->content = clean($subRange->content);
$subRange->slug = Str::slug($subRange->name);
});
static::updating(function (SubRange $subRange) {
$subRange->title = clean($subRange->title);
$subRange->content = clean($subRange->content);
$subRange->slug = Str::slug($subRange->name);
});
}
public function ranges()
{
return $this->belongsToMany(Range::class, 'range_sub_range');
}
}