P
Size: a a a
P
Iп
Iп
V
DS
А
А
K
Object of class Illuminate\Support\Carbon could not be converted to int
K
А
Object of class Illuminate\Support\Carbon could not be converted to int
YH
B
Object of class Illuminate\Support\Carbon could not be converted to int
K
public function __construct() {
/*Пишем ТВ программу в КЭШ */
$tvProgram = \View::share('tvProgram', \Cache::remember('tvProgram', now()->endOfDay(), static function () {
$collect = function (Carbon $start, Carbon $end) {
return \App\Tvprogramm::select('name', 'description', 'date')
->where('date', '>=', $start)
->where('date', '<=', $end)
->orderBy('date')
->get()
->map(static function ($item) {
return [
'name' => $item['name'],
'description' => $item['description'],
'date' => Carbon::create($item['date']),
];
});
};
return [
/*Берем программы ВЧЕРА СЕГОДНЯ ЗАВТРА и даем им соответствующие ключи*/
'yesterday' => $collect(now()->subDay()->startOfDay(), now()->subDay()->endOfDay()),
'today' => $collect(now()->startOfDay(), now()->endOfDay()),
'tomorrow'=> $collect(now()->addDays()->startOfDay(), now()->addDays()->endOfDay()),
];
}));
\View::share('tvNow', (static function () use ($tvProgram) {
$data = $tvProgram['today']
->mapToGroups(static function ($item) {
return [
now()->diffInSeconds($item['date'], false) > 0
? 'next'
: 'prev' => $item
];
});
$collection = collect($data->has('prev') ? [$data['prev']->last()] : []);
if($data->has('next')) {
$collection = $collection->merge($data['next']->slice(0, $collection->count() > 0 ? 2 : 3));
}
return $collection->count() < 3
? $collection->merge($tvProgram['tomorrow']->slice(0, abs($collection->count() - 3)))
: $collection;
}
)());
}
B
D
А
public function __construct() {
/*Пишем ТВ программу в КЭШ */
$tvProgram = \View::share('tvProgram', \Cache::remember('tvProgram', now()->endOfDay(), static function () {
$collect = function (Carbon $start, Carbon $end) {
return \App\Tvprogramm::select('name', 'description', 'date')
->where('date', '>=', $start)
->where('date', '<=', $end)
->orderBy('date')
->get()
->map(static function ($item) {
return [
'name' => $item['name'],
'description' => $item['description'],
'date' => Carbon::create($item['date']),
];
});
};
return [
/*Берем программы ВЧЕРА СЕГОДНЯ ЗАВТРА и даем им соответствующие ключи*/
'yesterday' => $collect(now()->subDay()->startOfDay(), now()->subDay()->endOfDay()),
'today' => $collect(now()->startOfDay(), now()->endOfDay()),
'tomorrow'=> $collect(now()->addDays()->startOfDay(), now()->addDays()->endOfDay()),
];
}));
\View::share('tvNow', (static function () use ($tvProgram) {
$data = $tvProgram['today']
->mapToGroups(static function ($item) {
return [
now()->diffInSeconds($item['date'], false) > 0
? 'next'
: 'prev' => $item
];
});
$collection = collect($data->has('prev') ? [$data['prev']->last()] : []);
if($data->has('next')) {
$collection = $collection->merge($data['next']->slice(0, $collection->count() > 0 ? 2 : 3));
}
return $collection->count() < 3
? $collection->merge($tvProgram['tomorrow']->slice(0, abs($collection->count() - 3)))
: $collection;
}
)());
}
B
YH