Agrega Productos y sus recetas
This commit is contained in:
@@ -11,6 +11,16 @@ class Producto extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'productos';
|
||||
protected $fillable = [
|
||||
'id', 'nombre', 'precio_venta', 'categoria_id',
|
||||
'zona_produccion_id', 'restaurante_id'
|
||||
];
|
||||
|
||||
public static function findOrFail($id) {
|
||||
$producto = Producto::find($id);
|
||||
if(!$producto) throw new ModelNotFoundException("producto", $id);
|
||||
return $producto;
|
||||
}
|
||||
|
||||
public function recetas() {
|
||||
return $this->hasMany(Receta::class, 'producto_id');
|
||||
|
||||
@@ -10,6 +10,7 @@ class Receta extends Model {
|
||||
use UuidPrimaryKey;
|
||||
|
||||
protected $table = 'recetas';
|
||||
protected $fillable = ['unidades', 'producto_id', 'ingrediente_id'];
|
||||
|
||||
public function ingrediente() {
|
||||
return $this->belongsTo(Ingrediente::class);
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\ZonaProduccion;
|
||||
use App\Models\Categoria;
|
||||
use App\Models\Proveedor;
|
||||
use App\Models\Ingrediente;
|
||||
use App\Models\Producto;
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use App\Exceptions\ModelNotFoundException;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -55,4 +56,8 @@ class Restaurante extends Model {
|
||||
public function ingredientes() {
|
||||
return $this->hasMany(Ingrediente::class, 'restaurante_id');
|
||||
}
|
||||
|
||||
public function productos() {
|
||||
return $this->hasMany(Producto::class, 'restaurante_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user