Current File : /home/tradevaly/new.tradevaly.com.bd/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')->where('sub_id', '!=', 0);
    }
    
    public function child(){
        return $this->belongsTo(Category::class, 'child_id', 'id')->where('child_id', '!=', 0);
    }
    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);
        });
    }
}