ldc-cocotte/app/Models/Products.php
Olivier Legat d4fba24e4a Bladification Boutique Canard
Breadcrumb (diglactic/laravel-breadcrumbs)
Gammes en AppService
Formattage Prix dans le model Products
route pour page : tous les produits
2021-03-15 17:44:35 +01:00

36 lines
948 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Products extends Model
{
use HasFactory;
use SoftDeletes;
protected $table = "products";
public function getFormattedPriceAttribute()
{
return $this->attributes['formattedPrice'] = sprintf('%s €', number_format($this->attributes['price'], 2, ',', ' '));
}
public function range() {
return $this->belongsTo('App\Models\Ranges', 'range_id');
}
public function old_slugs() {
return $this->hasMany('App\Model\OldSlug', 'product_id');
}
public function stats() {
return $this->hasMany('App\Models\Stats', 'product_id');
}
public function orders() {
return $this->belongsToMany('App\Models\Orders', 'orders_products', 'product_id', 'order_id')->withPivot('quantity');
}
}