From 2e62fcb8652ae9df67170a848d5fc4afd7d1f78f Mon Sep 17 00:00:00 2001 From: ale Date: Tue, 12 Mar 2024 17:05:15 -0300 Subject: [PATCH] =?UTF-8?q?relaci=C3=B3n=20producto=20-=20categor=C3=ADa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Producto.php | 8 ++++++ ...2_195543_add_categoria_id_to_productos.php | 28 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 database/migrations/2024_03_12_195543_add_categoria_id_to_productos.php diff --git a/app/Models/Producto.php b/app/Models/Producto.php index ee30aac..8695a73 100644 --- a/app/Models/Producto.php +++ b/app/Models/Producto.php @@ -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. */ diff --git a/database/migrations/2024_03_12_195543_add_categoria_id_to_productos.php b/database/migrations/2024_03_12_195543_add_categoria_id_to_productos.php new file mode 100644 index 0000000..6b5d249 --- /dev/null +++ b/database/migrations/2024_03_12_195543_add_categoria_id_to_productos.php @@ -0,0 +1,28 @@ +unsignedBigInteger('categoria_id')->after('id'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('productos', function (Blueprint $table) { + $table->dropColumn('categoria_id'); + }); + } +};