75 lines
1.7 KiB
PHP
75 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\PackagingItemFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class PackagingItem extends Model
|
|
{
|
|
/** @use HasFactory<PackagingItemFactory> */
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'packaging_material_id',
|
|
'supplier_id',
|
|
'name',
|
|
'category',
|
|
'weight_grams',
|
|
'min_stock_alert',
|
|
'url',
|
|
'product_id',
|
|
'active',
|
|
];
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'active' => 'boolean',
|
|
'weight_grams' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<PackagingMaterial, $this>
|
|
*/
|
|
public function packagingMaterial(): BelongsTo
|
|
{
|
|
return $this->belongsTo(PackagingMaterial::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Supplier, $this>
|
|
*/
|
|
public function supplier(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Supplier::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Product, $this>
|
|
*/
|
|
public function product(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Product::class);
|
|
}
|
|
|
|
/**
|
|
* Produkte, die diesen Verpackungsartikel in der Stückliste führen (BOM).
|
|
*
|
|
* @return BelongsToMany<Product, $this>
|
|
*/
|
|
public function products(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Product::class, 'product_packagings')
|
|
->withPivot('quantity', 'pos')
|
|
->withTimestamps();
|
|
}
|
|
}
|