Skip to content

Commit

Permalink
12. defective product model & migration
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrakovich committed Nov 3, 2024
1 parent 7e0caa3 commit f03d784
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/app/Models/DefectiveProduct.php
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);
}
}
3 changes: 3 additions & 0 deletions src/app/Providers/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public function panel(Panel $panel): Panel
'user' => NavigationGroup::make()
->label('Клиенты')
->icon('heroicon-o-user-group'),
'registry' => NavigationGroup::make()
->label('Реестры')
->icon('heroicon-o-folder'),
'old-admin-panel' => NavigationGroup::make()
->label('Старая админка')
->icon('heroicon-o-arrow-uturn-left')
Expand Down
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');
}
};
15 changes: 15 additions & 0 deletions src/stubs/model.stub
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'];
}

0 comments on commit f03d784

Please sign in to comment.