66 lines
1.5 KiB
PHP
66 lines
1.5 KiB
PHP
<?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 = [
|
|
'makerworld_id',
|
|
'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',
|
|
'makerworld_url',
|
|
'makerworld_author',
|
|
'makerworld_license',
|
|
'gallery_images',
|
|
'available_materials',
|
|
'available_colors',
|
|
];
|
|
|
|
protected $casts = [
|
|
'makerworld_id' => 'integer',
|
|
'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, ',', '.');
|
|
}
|
|
}
|