84 lines
1.7 KiB
PHP
84 lines
1.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use App\Enums\FoodType;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Support\Facades\Cache;
|
||
|
|
use Kwaadpepper\Enum\Traits\CastsEnums;
|
||
|
|
|
||
|
|
class CafelFood extends Model
|
||
|
|
{
|
||
|
|
use CastsEnums;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 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 = [
|
||
|
|
'delivery_date' => 'date'
|
||
|
|
];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Map attribute names to enum classes.
|
||
|
|
*
|
||
|
|
* @var array
|
||
|
|
*/
|
||
|
|
protected $enumCasts = [
|
||
|
|
'food_type' => FoodType::class
|
||
|
|
];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The attributes that are mass assignable.
|
||
|
|
*
|
||
|
|
* @var array
|
||
|
|
*/
|
||
|
|
protected $fillable = [
|
||
|
|
'batch_code',
|
||
|
|
'food_type',
|
||
|
|
'delivery_date'
|
||
|
|
];
|
||
|
|
|
||
|
|
// * METHODS
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get Food using cafel lot code
|
||
|
|
*
|
||
|
|
* @param \App\Enums\FoodType $food_type
|
||
|
|
* @param integer $codeLotCafel
|
||
|
|
* @return self|null
|
||
|
|
*/
|
||
|
|
public static function whereCodeLotCafel(FoodType $food_type, int $codeLotCafel): ?self
|
||
|
|
{
|
||
|
|
return Cache::remember("foodCafel$codeLotCafel", 5, function () use ($food_type, $codeLotCafel) {
|
||
|
|
return self::where(
|
||
|
|
'batch_code',
|
||
|
|
'LIKE',
|
||
|
|
'%' . \filter_var($codeLotCafel, \FILTER_SANITIZE_STRING) . '/%'
|
||
|
|
)->whereFoodType($food_type)->first();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|