<?php

namespace App\Models;

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

class SubCategory extends Model
{
    use HasFactory;
    
    public function category_list()
    {
        return $this->hasOne(Category::class,'id','cat_id');
    }
    
    public static function createSlug($title, $id = null)
    {
        $slug = Str::slug($title);
        $count = SubCategory::where('slug', $slug)->when($id, function ($query) use ($id) {
            return $query->where('id', '!=', $id);
        })->count();
        // dd($count);
        return $slug;
    }
    
}
