ldc-legaulois/app/Models/SubRange.php

36 lines
931 B
PHP
Raw Normal View History

2021-09-23 13:35:48 +02:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
2021-09-23 13:35:48 +02:00
class SubRange extends Model
{
protected $fillable = [
'name', 'picture_alt',
'back_link_url', 'back_link_text',
'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);
2021-09-23 13:35:48 +02:00
});
static::updating(function (SubRange $subRange) {
$subRange->title = clean($subRange->title);
$subRange->content = clean($subRange->content);
$subRange->slug = Str::slug($subRange->name);
2021-09-23 13:35:48 +02:00
});
}
public function ranges()
{
return $this->belongsToMany(Range::class, 'range_sub_range');
}
}