class Product extends Model
{
use HasFactory;
protected $primaryKey = "p_Id";
public function category()
{
return $this->belongsTo(App\Models\Category::class, 'C_Id');
}
}
class Category extends Model
{
use HasFactory;
protected $primaryKey = "C_ID";
public function products()
{
return $this->hasMany(App\Models\Product::class, 'C_ID');
}
}
Schema::create('products', function (Blueprint $table) {
$table->id('p_Id');
$table->foreignId('C_ID')->constrained('categories');
$table->string('Title');
$table->text('Description');
$table->string('Image');
$table->decimal('Price', 10, 2);
$table->decimal('Sale', 10, 2)->nullable();
$table->timestamps();
});
}