ldc-doux/app/Models/Product.php
2022-01-06 17:50:26 +01:00

59 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use App\Lib\Utils;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
use HasFactory;
protected $fillable = [
'gamme_id',
'name',
'slug',
'description',
'picture',
'alt_text_picture',
'pictos',
'plusproduit',
'is_published',
'is_on_top',
'is_halal',
'is_food_service',
'seo_title',
'seo_description',
];
protected static function boot()
{
static::creating(function (Product $product) {
if ($product->picture) {
$product->picture = Utils::storeImage($product->picture, $product->getTable());
}
if ($product->banner) {
$product->banner = Utils::storeImage($product->banner, $product->getTable());
}
});
static::updating(function (Product $product) {
if ($product->picture) {
$product->picture = Utils::storeImage($product->picture, $product->getTable());
}
if ($product->banner) {
$product->banner = Utils::storeImage($product->banner, $product->getTable());
}
});
parent::boot();
}
/**
* Get the Range that owns the product.
*/
public function gamme()
{
return $this->belongsTo(Gamme::class);
}
}