relación producto - categoría

This commit is contained in:
Alejandro Tasistro 2024-03-12 17:05:15 -03:00
parent ed1cc787c2
commit 2e62fcb865
2 changed files with 36 additions and 0 deletions

View File

@ -7,6 +7,14 @@
class Producto extends Model
{
/**
* La categoría a la que pertenece el producto.
*/
public function categoria(): BelongsTo
{
return $this->belongsTo(Categoria::class);
}
/**
* Los pedidos que tienen al producto.
*/

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::table('productos', function (Blueprint $table) {
$table->unsignedBigInteger('categoria_id')->after('id');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('productos', function (Blueprint $table) {
$table->dropColumn('categoria_id');
});
}
};