ldc-legaulois/app/Models/SubRange.php

62 lines
1.4 KiB
PHP
Raw Normal View History

2021-09-23 13:35:48 +02:00
<?php
namespace App\Models;
2021-10-22 10:52:32 +02:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
2021-09-23 13:35:48 +02:00
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
2021-09-23 13:35:48 +02:00
class SubRange extends Model
{
2021-10-22 10:52:32 +02:00
use HasFactory;
2021-09-23 13:35:48 +02:00
2022-05-05 13:05:02 +00:00
/**
* The model's attributes.
*
* @var array
*/
2021-11-22 16:39:16 +01:00
protected $attributes = [
'back_link_url' => '',
'back_link_text' => ''
];
2022-05-05 13:05:02 +00:00
/**
* The attributes that are mass assignable.
*
* @var array
*/
2021-09-23 13:35:48 +02:00
protected $fillable = [
'name', 'picture_alt',
'back_link_url', 'back_link_text',
'back_link_display', 'title',
'subtitle', 'content'
2021-09-23 13:35:48 +02:00
];
2022-05-05 13:05:02 +00:00
/**
* Perform any actions required after the model boots.
*
* @return void
*/
2021-09-23 13:35:48 +02:00
protected static function booted()
{
static::creating(function (SubRange $subRange) {
$subRange->content = clean($subRange->content);
2022-02-10 16:14:58 +01:00
$subRange->slug = Str::slug($subRange->name);
2021-09-23 13:35:48 +02:00
});
static::updating(function (SubRange $subRange) {
$subRange->content = clean($subRange->content);
2022-02-10 16:14:58 +01:00
$subRange->slug = Str::slug($subRange->name);
2021-09-23 13:35:48 +02:00
});
}
2022-05-05 13:05:02 +00:00
/**
* BelongsToMany ranges relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
2021-09-23 13:35:48 +02:00
public function ranges()
{
return $this->belongsToMany(Range::class, 'range_sub_range');
}
}