Current File : /home/tradevaly/www/app/Models/Product.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\SoftDeletes;

class Product extends Model
{
    use HasFactory,SoftDeletes;
    
   public function category(){
        return $this->belongsTo(Category::class);
    }
    
    public function sub(){
        return $this->belongsTo(Category::class, 'sub_id', 'id');
    }
    
    public function child(){
        return $this->belongsTo(Category::class, 'child_id', 'id');
    }
    public function supplier(){
        return $this->belongsTo(Company::class, 'supplier_id', 'user_id');
    }
    public function message(){
        return $this->hasMany(Thread::class);
    }
    public function thumbs(){
        return $this->hasMany(Thumb::class);
    }
    public function country(){
        return $this->belongsTo(Country::class);
    }
    protected static function boot() {
        parent::boot();

        static::creating(function ($question) {
            $question->slug = Str::slug($question->title);
        });
    }
    // protected static function price()
    // {
    //     return $this->belongsTo(ProductPrice::class);
    // }
}