From 12634329bc637fce4434b410064a580dbed4746d Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 11 Mar 2024 19:41:52 -0300 Subject: [PATCH] definiciones y migraciones de pedido --- app/Models/Barrio.php | 8 +++++ app/Models/Pedido.php | 27 +++++++++++++++++ ...2024_03_11_221942_create_pedidos_table.php | 30 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 app/Models/Pedido.php create mode 100644 database/migrations/2024_03_11_221942_create_pedidos_table.php 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..957f298 --- /dev/null +++ b/app/Models/Pedido.php @@ -0,0 +1,27 @@ + + */ + protected $fillable = [ + 'name', + ]; + + /** + * El barrio al que pertenece el pedido. + */ + public function barrio(): BelongsTo + { + return $this->belongsTo(Barrio::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'); + } +};