@MicroCl

ErrorException in PagesController.php line 477: Trying to get property 'date' of non-object В чем проблема?

Выдает такую ошибку:
in PagesController.php line 477
at HandleExceptions->handleError('8', 'Trying to get property 'date' of non-object', '/var/www/www-root/data/www/gamingbets.ru/app/Http/Controllers/PagesController.php', '477', array('history' => object(Collection), 'lives' => object(Collection), 'coming' => object(Collection), 'latest' => null)) in PagesController.php line 477

Код:
public function index(){
        $history = History::where('id','>',0)->orderBy('id','desc')->limit(3)->get();
        $lives = Tournaments::where('live',1)->where('status',1)->get();
        $coming = Tournaments::where('live',0)->where('status',0)
            ->where('team1','!=','no team1')
            ->where('team2','!=','no team2')
            ->where('date','>=',Carbon::now()->timestamp)
            ->orderBy('date','ASC')
            ->take(10)
            ->get();
        $latest = Tournaments::where('live',0)->where('status',0)->where('date','>=',Carbon::now()->timestamp)->orderBy('date','ASC')->first();
        $last = Carbon::createFromTimestamp($latest->date)->toDateTimeString(); // 477 строка
        if(count($lives) == 0){
            $c = 0;
        }else{
            $c = 1;
        }
        if(count($coming) == 0){
            $pages = 1;
        }else{
            $pages = round(count($coming)/10);
        }


Прошу помощи, весь день убил на поиск решения.
  • Вопрос задан
  • 106 просмотров
Пригласить эксперта
Ответы на вопрос 1
@mShpakov
Проверки на нул сами себя не сделают
public function index(){
$history = History::where('id','>',0)->orderBy('id','desc')->limit(3)->get();
$lives = Tournaments::where('live',1)->where('status',1)->get();
$coming = Tournaments::where('live',0)->where('status',0)
->where('team1','!=','no team1')
->where('team2','!=','no team2')
->where('date','>=',Carbon::now()->timestamp)
->orderBy('date','ASC')
->take(10)
->get();
$latest = Tournaments::where('live',0)->where('status',0)->where('date','>=',Carbon::now()->timestamp)->orderBy('date','ASC')->first();
if($latest){
$last = Carbon::createFromTimestamp($latest->date)->toDateTimeString();
if(count($lives) == 0){
$c = 0;
}else{
$c = 1;
}
if(count($coming) == 0){
$pages = 1;
}else{
$pages = round(count($coming)/10);
}
}
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы