diff --git a/app/Models/Barrio.php b/app/Models/Barrio.php index 02384cc..9c48da6 100644 --- a/app/Models/Barrio.php +++ b/app/Models/Barrio.php @@ -23,4 +23,12 @@ public function region(): BelongsTo { return $this->belongsTo(Region::class); } + + /** + * Los pedidos que pertenecen al barrio. + */ + public function pedidos(): HasMany + { + return $this->hasMany(Pedido::class); + } } diff --git a/app/Models/Pedido.php b/app/Models/Pedido.php new file mode 100644 index 0000000..31bd7be --- /dev/null +++ b/app/Models/Pedido.php @@ -0,0 +1,34 @@ + + */ + protected $fillable = [ + 'name', + ]; + + /** + * El barrio al que pertenece el pedido. + */ + public function barrio(): BelongsTo + { + return $this->belongsTo(Barrio::class); + } + + /** + * Los productos que pertenecen al pedido. + */ + public function productos(): BelongsToMany + { + return $this->belongsToMany(Producto::class); + } +} diff --git a/app/Models/Producto.php b/app/Models/Producto.php new file mode 100644 index 0000000..ee30aac --- /dev/null +++ b/app/Models/Producto.php @@ -0,0 +1,17 @@ +belongsToMany(Pedido::class); + } +} diff --git a/database/migrations/2024_03_11_221942_create_pedidos_table.php b/database/migrations/2024_03_11_221942_create_pedidos_table.php new file mode 100644 index 0000000..2848a1b --- /dev/null +++ b/database/migrations/2024_03_11_221942_create_pedidos_table.php @@ -0,0 +1,30 @@ +id(); + $table->string('name', 100); + $table->unsignedBigInteger('barrio_id'); + $table->foreign('barrio_id')->references('id')->on('barrios'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('pedidos'); + } +}; diff --git a/database/migrations/2024_03_11_224041_create_productos_table.php b/database/migrations/2024_03_11_224041_create_productos_table.php new file mode 100644 index 0000000..e524043 --- /dev/null +++ b/database/migrations/2024_03_11_224041_create_productos_table.php @@ -0,0 +1,27 @@ +id(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('productos'); + } +}; diff --git a/database/migrations/2024_03_11_224437_create_productos_pedidos_table.php b/database/migrations/2024_03_11_224437_create_productos_pedidos_table.php new file mode 100644 index 0000000..e61e66b --- /dev/null +++ b/database/migrations/2024_03_11_224437_create_productos_pedidos_table.php @@ -0,0 +1,32 @@ +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'); + } +};