feature/modelos-y-migraciones #3
					 2 changed files with 39 additions and 0 deletions
				
			
		| 
						 | 
					@ -24,4 +24,11 @@ class Pedido extends Model
 | 
				
			||||||
        return $this->belongsTo(Barrio::class);
 | 
					        return $this->belongsTo(Barrio::class);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Los productos que pertenecen al pedido.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function productos(): BelongsToMany
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return $this->belongsToMany(Producto::class);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,32 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Illuminate\Database\Migrations\Migration;
 | 
				
			||||||
 | 
					use Illuminate\Database\Schema\Blueprint;
 | 
				
			||||||
 | 
					use Illuminate\Support\Facades\Schema;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					return new class extends Migration
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Run the migrations.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function up(): void
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        Schema::create('productos_pedidos', function (Blueprint $table) {
 | 
				
			||||||
 | 
					            $table->id();
 | 
				
			||||||
 | 
					            $table->unsignedBigInteger('pedido_id');
 | 
				
			||||||
 | 
					            $table->unsignedBigInteger('producto_id');
 | 
				
			||||||
 | 
					            $table->unsignedInteger('ammount');
 | 
				
			||||||
 | 
					            $table->timestamps();
 | 
				
			||||||
 | 
					            $table->foreign('pedido_id')->references('id')->on('pedidos');
 | 
				
			||||||
 | 
					            $table->foreign('producto_id')->references('id')->on('productos');
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Reverse the migrations.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function down(): void
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        Schema::dropIfExists('productos_pedidos');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue