-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
12. defective product model & migration
- Loading branch information
1 parent
7e0caa3
commit f03d784
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
/** | ||
* @property int $id | ||
* @property int $product_id id товара | ||
* @property int $size_id id размера | ||
* @property string|null $reason Причина добавления в брак | ||
* @property \Illuminate\Support\Carbon|null $created_at | ||
* @property \Illuminate\Support\Carbon|null $updated_at | ||
* | ||
* @property-read \App\Models\Product|null $product | ||
* @property-read \App\Models\Size|null $size | ||
* | ||
* @mixin \Illuminate\Database\Eloquent\Builder | ||
*/ | ||
class DefectiveProduct extends Model | ||
{ | ||
/** | ||
* The attributes that aren't mass assignable. | ||
* | ||
* @var array<string>|bool | ||
*/ | ||
protected $guarded = ['id']; | ||
|
||
/** | ||
* Get the product associated with the defective product. | ||
*/ | ||
public function product(): BelongsTo | ||
{ | ||
return $this->belongsTo(Product::class)->withTrashed(); | ||
} | ||
|
||
/** | ||
* Get the product size associated with the defective product. | ||
* | ||
* @return BelongsTo | ||
*/ | ||
public function size(): BelongsTo | ||
{ | ||
return $this->belongsTo(Size::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/database/migrations/2024_11_03_202859_create_defective_products_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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('defective_products', function (Blueprint $table) { | ||
$table->id(); | ||
$table->foreignId('product_id')->comment('id товара')->constrained('products')->cascadeOnUpdate()->cascadeOnDelete(); | ||
$table->foreignId('size_id')->comment('id размера')->constrained('sizes')->cascadeOnUpdate()->cascadeOnDelete(); | ||
$table->string('reason')->nullable()->comment('Причина добавления в брак'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('defective_products'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace {{ namespace }}; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class {{ class }} extends Model | ||
{ | ||
/** | ||
* The attributes that aren't mass assignable. | ||
* | ||
* @var array<string>|bool | ||
*/ | ||
protected $guarded = ['id']; | ||
} |