ldc-boutique-cnc/app/Models/Shop/Timeslot.php
2023-05-17 11:41:07 +02:00

77 lines
1.6 KiB
PHP

<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @property string $order_id
* @property \Carbon\Carbon $slot
* @package App\Models\Shop
*/
class Timeslot extends Model
{
use HasFactory;
use SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'order_id', 'shop_id', 'slot'
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'slot' => 'datetime'
];
// * RELATIONSHIPS
/**
* BelongsTo order relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function order()
{
return $this->belongsTo(Order::class);
}
/**
* BelongsTo shop relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function shop()
{
return $this->belongsTo(Shop::class);
}
// * METHODS
/**
* Supprimer les comptes inactivés depuis plus d'une semaine
* de manière permanente.
*
* ! Les timeslot qui :
* ! - ont un order non existant (le customer n ést pas allé jusque bout)
*
* @return \Illuminate\Database\Query\Builder
*/
public function prunable()
{
return static::query()->where(function (Builder $q) {
$q->whereDoesntHave('order');
});
}
}