2020-09-21 11:03:50 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2021-09-23 15:14:14 +02:00
|
|
|
use Illuminate\Support\Str;
|
2020-09-21 11:03:50 +02:00
|
|
|
|
2021-09-21 09:26:21 +02:00
|
|
|
class Range extends Model
|
2020-09-21 11:03:50 +02:00
|
|
|
{
|
2021-09-23 15:14:14 +02:00
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-02 10:26:36 +01:00
|
|
|
public function products()
|
|
|
|
|
{
|
2021-02-09 09:50:17 +01:00
|
|
|
return $this->hasMany(Products::class, 'range_id');
|
2020-10-06 17:34:41 +02:00
|
|
|
}
|
2020-12-17 17:15:06 +01:00
|
|
|
|
2021-02-02 10:26:36 +01:00
|
|
|
public function reductions()
|
|
|
|
|
{
|
2021-10-13 12:06:41 +02:00
|
|
|
return $this->belongsToMany(Reduction::class, 'reduction_config', 'range_id', 'reduction_id');
|
2020-12-17 17:15:06 +01:00
|
|
|
}
|
2021-09-23 13:35:48 +02:00
|
|
|
|
|
|
|
|
public function subRanges()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(SubRange::class, 'range_sub_range');
|
|
|
|
|
}
|
2020-09-21 11:03:50 +02:00
|
|
|
}
|