create crud product categories and partial update crud products with dealers stock

This commit is contained in:
2025-05-28 18:24:44 +07:00
parent 80375d8af3
commit 59e23ae535
28 changed files with 1336 additions and 28 deletions

View File

@@ -22,4 +22,10 @@ class Dealer extends Model
{
return $this->hasMany(Transaction::class, 'dealer_id', 'id');
}
public function products(){
return $this->belongsToMany(Product::class, 'stock')
->withPivot('quantity')
->withTimestamps();
}
}

24
app/Models/Product.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Product extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = ['code','name','description','product_category_id'];
public function category(){
return $this->belongsTo(ProductCategory::class, 'product_category_id');
}
public function dealers(){
return $this->belongsToMany(Dealer::class, 'stock')
->withPivot('quantity')
->withTimestamps();
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class ProductCategory extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = ['name'];
public function products(){
return $this->hasMany(Product::class, 'product_category_id');
}
}