-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlProducto.php
More file actions
37 lines (30 loc) · 1.11 KB
/
BlProducto.php
File metadata and controls
37 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class BlProducto extends Model
{
protected $table = 'bl_productos';
protected $fillable = ['tipo_producto', 'tamanio', 'color_id', 'cantidad_por_empaque', 'codigo_barras', 'descripcion'];
// Relación: Un producto pertenece a un color
public function color(): BelongsTo
{
return $this->belongsTo(BlColor::class, 'color_id');
}
// Relación: Un producto puede tener muchos empaques
public function empaques(): HasMany
{
return $this->hasMany(BlEmpaque::class, 'producto_id');
}
// ✅ Relación DIRECTA con inventarioDetalle (usando producto_id)
public function inventarioDetalle(): HasMany
{
return $this->hasMany(BlInventarioDetalle::class, 'producto_id');
}
// Accesor: Descripción automática (ej: "BT 20MM Dorado")
public function getDescripcionAttribute(): string
{
return "{$this->tipo_producto} {$this->tamanio} {$this->color->codigo}";
}
}