<?php

namespace App\Models;

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

class Brand extends Model
{
    use HasFactory;
    
    public static function createSlug($title, $id = null)
    {
        $slug = Str::slug($title);
        $count = Brand::where('slug', $slug)->when($id, function ($query) use ($id) {
            return $query->where('id', '!=', $id);
        })->count();

        return $count ? "{$slug}-{$count}" : $slug;
    }
    
}
