definiciones y migraciones de pedido

This commit is contained in:
Alejandro Tasistro 2024-03-11 19:41:52 -03:00
parent 2a5cf1ccd9
commit 12634329bc
3 changed files with 65 additions and 0 deletions

View File

@ -23,4 +23,12 @@ public function region(): BelongsTo
{ {
return $this->belongsTo(Region::class); 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');
}
};