70 lines
1.4 KiB
PHP
70 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class CafelPoultryMiseEnPlace extends Model
|
|
{
|
|
/**
|
|
* The primary key for the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $primaryKey = 'batch_code';
|
|
|
|
/**
|
|
* Indicates if the IDs are auto-incrementing.
|
|
*
|
|
* @var boolean
|
|
*/
|
|
public $incrementing = false;
|
|
|
|
/**
|
|
* Indicates if the model should be timestamped.
|
|
*
|
|
* @var boolean
|
|
*/
|
|
public $timestamps = false;
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'transfert_date' => 'date',
|
|
'inuav_codes' => 'array'
|
|
];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'batch_code',
|
|
'inuav_codes',
|
|
'transfert_date'
|
|
];
|
|
|
|
// * METHODS
|
|
|
|
/**
|
|
* Get Mep using cafel lot code
|
|
*
|
|
* @param integer $codeLotCafel
|
|
* @return self|null
|
|
*/
|
|
public static function whereCodeLotCafel(int $codeLotCafel): ?self
|
|
{
|
|
return Cache::remember("poultryMep$codeLotCafel", 5, function () use ($codeLotCafel) {
|
|
return self::where(
|
|
'batch_code',
|
|
'LIKE',
|
|
'%' . \filter_var($codeLotCafel, \FILTER_SANITIZE_STRING) . '/%'
|
|
)->first();
|
|
});
|
|
}
|
|
}
|