<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Fornecedor extends Model
{
    use SoftDeletes;


    protected $dates = ['deleted_at'];

    protected $primaryKey = 'id';

    
    protected $table = 'fornecedor';


  
    public static function existeFornecedor($slug, $lang, $id)
    {

        if ($id != 0) {
            $existe = Fornecedor::where('slug', '=', $slug)
                ->where('id', '<>', $id)->get();
        } else {
            $existe = Fornecedor::where('slug', '=', $slug)->get();
        }

        if (count($existe) > 0) {
            $slug = $slug . (count($existe));
        }

        return $slug;
    }


     
   

   
}
