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 CafelBeaPoultry extends Model
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* The primary key for the model.
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected $primaryKey = null;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 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 = [
|
||
|
|
'last_audit_date' => 'date'
|
||
|
|
];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The attributes that are mass assignable.
|
||
|
|
*
|
||
|
|
* @var array
|
||
|
|
*/
|
||
|
|
protected $fillable = [
|
||
|
|
'bea_code',
|
||
|
|
'batch_code',
|
||
|
|
'last_audit_date'
|
||
|
|
];
|
||
|
|
|
||
|
|
// * METHODS
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get Bea using cafel lot code
|
||
|
|
*
|
||
|
|
* @param integer $codeLotCafel
|
||
|
|
* @return self|null
|
||
|
|
*/
|
||
|
|
public static function whereCodeLotCafel(int $codeLotCafel): ?self
|
||
|
|
{
|
||
|
|
return Cache::remember("beaCafel$codeLotCafel", 5, function () use ($codeLotCafel) {
|
||
|
|
return self::where(
|
||
|
|
'batch_code',
|
||
|
|
'LIKE',
|
||
|
|
'%' . \filter_var($codeLotCafel, \FILTER_SANITIZE_STRING) . '/%'
|
||
|
|
)->first();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|