ldc-legaulois/app/Models/Range.php
2021-09-23 15:14:14 +02:00

52 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
class Range extends Model
{
protected $attributes = [
'flagship_product' => null
];
protected $fillable = [
'name', 'description', 'color', 'status', 'flagship_product'
];
protected static function booted()
{
static::creating(function (Range $range) {
$range->slug = Str::slug($range->name);
});
static::updating(function (Range $range) {
$range->slug = Str::slug($range->name);
});
}
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'color' => HtmlColor::class
];
public function products()
{
return $this->hasMany(Products::class, 'range_id');
}
public function reductions()
{
return $this->belongsToMany(Reductions::class, 'reduction_config', 'range_id', 'reduction_id');
}
public function subRanges()
{
return $this->belongsToMany(SubRange::class, 'range_sub_range');
}
}