ldc-legaulois/app/Models/Range.php

43 lines
959 B
PHP
Raw Normal View History

2020-09-21 11:03:50 +02:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
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
{
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()
{
2021-02-09 09:50:17 +01:00
return $this->hasMany(Products::class, 'range_id');
}
public function reductions()
{
2021-10-13 12:06:41 +02:00
return $this->belongsToMany(Reduction::class, 'reduction_config', 'range_id', 'reduction_id');
}
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
}