<?php

namespace App;

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

class Video extends Model
{
    use SoftDeletes;

    protected $dates = ['deleted_at'];

    protected $primaryKey = 'id';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'description', 'image', 'link', 'language_id', 'slug',
    ];

    public static function existeVideo($slug, $id){
        
        if ($id != 0) {
            $existe = Video::where('slug', '=', $slug)
                                  ->where('id', '<>', $id)->get();
        } else {
            $existe = Video::where('slug', '=', $slug)->get();
        }

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

        return $slug;
    }
}
