Initial commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'category_id',
|
||||
'name',
|
||||
'slug',
|
||||
'short_description',
|
||||
'description',
|
||||
'base_price',
|
||||
'sku',
|
||||
'is_print_on_demand',
|
||||
'stock',
|
||||
'is_featured',
|
||||
'is_active',
|
||||
'dimensions',
|
||||
'weight_grams',
|
||||
'print_time_hours',
|
||||
'image_url',
|
||||
'gallery_images',
|
||||
'available_materials',
|
||||
'available_colors',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'base_price' => 'float',
|
||||
'is_print_on_demand' => 'boolean',
|
||||
'is_featured' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
'print_time_hours' => 'float',
|
||||
'gallery_images' => 'array',
|
||||
'available_materials' => 'array',
|
||||
'available_colors' => 'array',
|
||||
];
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function orderItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(OrderItem::class);
|
||||
}
|
||||
|
||||
public function getFormattedPriceAttribute(): string
|
||||
{
|
||||
return '€ ' . number_format($this->base_price, 2, ',', '.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user