From eba87feb91a24f8c14ddd4f07454d9da850e5f8f Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 11 Mar 2024 19:08:31 -0300 Subject: [PATCH 1/3] definiciones y migraciones de region y barrio --- app/Models/Barrio.php | 26 +++++++++++++++ app/Models/Region.php | 33 +++++++++++++++++++ ...2024_03_11_205603_create_regions_table.php | 28 ++++++++++++++++ ...2024_03_11_210402_create_barrios_table.php | 30 +++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 app/Models/Barrio.php create mode 100644 app/Models/Region.php create mode 100644 database/migrations/2024_03_11_205603_create_regions_table.php create mode 100644 database/migrations/2024_03_11_210402_create_barrios_table.php diff --git a/app/Models/Barrio.php b/app/Models/Barrio.php new file mode 100644 index 0000000..02384cc --- /dev/null +++ b/app/Models/Barrio.php @@ -0,0 +1,26 @@ + + */ + protected $fillable = [ + 'name', + ]; + + /** + * La región a la que pertenece el barrio. + */ + public function region(): BelongsTo + { + return $this->belongsTo(Region::class); + } +} diff --git a/app/Models/Region.php b/app/Models/Region.php new file mode 100644 index 0000000..53ddecb --- /dev/null +++ b/app/Models/Region.php @@ -0,0 +1,33 @@ + + */ + protected $fillable = [ + 'name', + ]; + + /** + * Los barrios que pertenecen a la región. + */ + public function barrios(): HasMany + { + return $this->hasMany(Barrio::class); + } +} diff --git a/database/migrations/2024_03_11_205603_create_regions_table.php b/database/migrations/2024_03_11_205603_create_regions_table.php new file mode 100644 index 0000000..ee523be --- /dev/null +++ b/database/migrations/2024_03_11_205603_create_regions_table.php @@ -0,0 +1,28 @@ +id(); + $table->timestamps(); + $table->string('name', 100); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('regiones'); + } +}; diff --git a/database/migrations/2024_03_11_210402_create_barrios_table.php b/database/migrations/2024_03_11_210402_create_barrios_table.php new file mode 100644 index 0000000..4c16a65 --- /dev/null +++ b/database/migrations/2024_03_11_210402_create_barrios_table.php @@ -0,0 +1,30 @@ +id(); + $table->timestamps(); + $table->string('name', 100); + $table->unsignedBigInteger('region_id'); + $table->foreign('region_id')->references('id')->on('regiones'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('barrios'); + } +}; From 2f29b1c34c4020923244268b8acafc7146089762 Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 11 Mar 2024 19:09:03 -0300 Subject: [PATCH 2/3] seeder de barrio con barrio prueba de region prueba --- database/seeders/BarrioSeeder.php | 27 +++++++++++++++++++++++++++ database/seeders/DatabaseSeeder.php | 9 +++------ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 database/seeders/BarrioSeeder.php diff --git a/database/seeders/BarrioSeeder.php b/database/seeders/BarrioSeeder.php new file mode 100644 index 0000000..595f278 --- /dev/null +++ b/database/seeders/BarrioSeeder.php @@ -0,0 +1,27 @@ +insert([ + ['name'=>'PRUEBA', 'created_at'=>Date::now()] + ]); + + $prueba_id = DB::table('regiones')->where('name','PRUEBA')->first()->id; + + DB::table('barrios')->insert([ + ['name'=>'PRUEBA','region_id'=>$prueba_id, 'created_at'=>Date::now()], + ]); + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index a9f4519..9e2405c 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -12,11 +12,8 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - // \App\Models\User::factory(10)->create(); - - // \App\Models\User::factory()->create([ - // 'name' => 'Test User', - // 'email' => 'test@example.com', - // ]); + $this->call([ + BarrioSeeder::class, + ]); } } From 2a5cf1ccd99af5f8aac299184d4b4103d7f42440 Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 11 Mar 2024 19:13:06 -0300 Subject: [PATCH 3/3] Cambio orden columnas --- database/migrations/2024_03_11_205603_create_regions_table.php | 2 +- database/migrations/2024_03_11_210402_create_barrios_table.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/database/migrations/2024_03_11_205603_create_regions_table.php b/database/migrations/2024_03_11_205603_create_regions_table.php index ee523be..8417e86 100644 --- a/database/migrations/2024_03_11_205603_create_regions_table.php +++ b/database/migrations/2024_03_11_205603_create_regions_table.php @@ -13,8 +13,8 @@ public function up(): void { Schema::create('regiones', function (Blueprint $table) { $table->id(); - $table->timestamps(); $table->string('name', 100); + $table->timestamps(); }); } diff --git a/database/migrations/2024_03_11_210402_create_barrios_table.php b/database/migrations/2024_03_11_210402_create_barrios_table.php index 4c16a65..8d1352e 100644 --- a/database/migrations/2024_03_11_210402_create_barrios_table.php +++ b/database/migrations/2024_03_11_210402_create_barrios_table.php @@ -13,10 +13,10 @@ public function up(): void { Schema::create('barrios', function (Blueprint $table) { $table->id(); - $table->timestamps(); $table->string('name', 100); $table->unsignedBigInteger('region_id'); $table->foreign('region_id')->references('id')->on('regiones'); + $table->timestamps(); }); }