mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
fix php error for HasParcelWithTransportBetweenDate
This commit is contained in:
@@ -10,17 +10,26 @@ class HasParcelWithTransportBetweenDate implements Filter
|
||||
{
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
if (is_string($value)) $value = json_decode($value, true) ?? [];
|
||||
if (is_string($value)) {
|
||||
$value = json_decode($value, true) ?? [];
|
||||
}
|
||||
|
||||
$start = Carbon::make(data_get($value, 'start_date'))?->startOfDay();
|
||||
$end = Carbon::make(data_get($value, 'end_date'))?->endOfDay();
|
||||
$startDate = Carbon::make(data_get($value, 'start_date'));
|
||||
$endDate = Carbon::make(data_get($value, 'end_date'));
|
||||
|
||||
$start = $startDate ? $startDate->startOfDay() : null;
|
||||
$end = $endDate ? $endDate->endOfDay() : null;
|
||||
|
||||
if (!$start && !$end) return $builder;
|
||||
if ($start && $end && $start->gt($end)) [$start, $end] = [$end, $start];
|
||||
|
||||
return $builder->whereHas('transports', function (Builder $q) use ($start, $end) {
|
||||
if ($start && $end && $start->isSameDay($end)) return $q->whereDate('drop_date', $start->toDateString());
|
||||
if ($start && $end) return $q->whereBetween('drop_date', [$start, $end]);
|
||||
if ($start && $end && $start->isSameDay($end)) {
|
||||
return $q->whereDate('drop_date', $start->toDateString());
|
||||
}
|
||||
if ($start && $end) {
|
||||
return $q->whereBetween('drop_date', [$start, $end]);
|
||||
}
|
||||
return $start
|
||||
? $q->where('drop_date', '>=', $start)
|
||||
: $q->where('drop_date', '<=', $end);
|
||||
|
||||
Reference in New Issue
Block a user