<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = ['label', 'picture', 'about', 'quantity', 'quantityalert', 'category', 'code', 'state', 'price'];

    //Control the unicity of the code
    
    public static function codeunique($code){
    	//Count how many time this code fugure in the product table, if it more or equal to once the fuction return false in other case it return true.

    	$ManyTime = Product::whereCode($code)->count('id');

    	if($ManyTime>0){
    		return false;
    	}else{
    		return true;
    	}
    }
}
