ldc-legaulois/app/Models/SubRange.php
Jérémy Munsch 5989c04414 Ticket852
2022-05-05 13:05:02 +00:00

61 lines
1.4 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;
/**
* The model's attributes.
*
* @var array
*/
protected $attributes = [
'back_link_url' => '',
'back_link_text' => ''
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'picture_alt',
'back_link_url', 'back_link_text',
'back_link_display', 'title',
'subtitle', 'content'
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted()
{
static::creating(function (SubRange $subRange) {
$subRange->content = clean($subRange->content);
$subRange->slug = Str::slug($subRange->name);
});
static::updating(function (SubRange $subRange) {
$subRange->content = clean($subRange->content);
$subRange->slug = Str::slug($subRange->name);
});
}
/**
* BelongsToMany ranges relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function ranges()
{
return $this->belongsToMany(Range::class, 'range_sub_range');
}
}