feature/modelos-y-migraciones #3

Merged
rho merged 28 commits from feature/modelos-y-migraciones into master 2024-03-14 16:34:44 -03:00
4 changed files with 117 additions and 0 deletions
Showing only changes of commit eba87feb91 - Show all commits

26
app/Models/Barrio.php Normal file
View File

@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Barrio extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
];
/**
* La región a la que pertenece el barrio.
*/
public function region(): BelongsTo
{
return $this->belongsTo(Region::class);
}
}

33
app/Models/Region.php Normal file
View File

@ -0,0 +1,33 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Region extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'regiones';
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
];
/**
* Los barrios que pertenecen a la región.
*/
public function barrios(): HasMany
{
return $this->hasMany(Barrio::class);
}
}

View File

@ -0,0 +1,28 @@
<?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('regiones', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('name', 100);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('regiones');
}
};

View File

@ -0,0 +1,30 @@
<?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('barrios', function (Blueprint $table) {
$table->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');
}
};