File: //home/marketing.cfbon.ru/public_html/app/Models/Volume.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Volume extends Model
{
protected $table = 'volumes';
protected $fillable = [
'name',
'size',
];
public function getSizeTitleAttribute() : string
{
return $this->size . ' ml';
}
public function getTitleAttribute() : string
{
return "$this->name - $this->size_title";
}
public function products() : BelongsToMany
{
return $this->belongsToMany(Product::class, 'product_volumes')
->withPivot('price')
->withTimestamps();
}
}