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
3 changed files with 65 additions and 0 deletions
Showing only changes of commit 12634329bc - Show all commits

View File

@ -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);
}
}

27
app/Models/Pedido.php Normal file
View File

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

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('pedidos', function (Blueprint $table) {
$table->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');
}
};