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

42 lines
959 B
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);
});
}
public function products()
{
return $this->hasMany(Products::class, 'range_id');
}
public function reductions()
{
return $this->belongsToMany(Reduction::class, 'reduction_config', 'range_id', 'reduction_id');
}
public function subRanges()
{
return $this->belongsToMany(SubRange::class, 'range_sub_range');
}
}