Я пытаюсь получить результаты из союза, показывая только результаты, которые были обновлены после того, как я в последний раз проверил (определяется в $ last_check)Сравнение временных меток из двух разных таблиц в Laravel 5
$last_check = CheckNotifications::where('notif_check_user_id', '=', $user_id)->pluck('updated_at');
$get_projects = DB::table('requests')
->join('notifications', 'notifications.notif_project_id', '=', 'requests.id')
->select(DB::raw('requests.updated_at, requests.request_name, "" as fullname, "P" as flag'))
->where('notif_user_id', '=', $user_id)
->whereRaw('requests.updated_at > requests.created_at');
$comments = DB::table('project_comments')
->leftJoin('users', 'comment_user_id', '=', 'users.id')
->leftJoin('requests', 'comment_project_id', '=', 'requests.id')
->select(DB::raw('project_comments.updated_at, requests.request_name, users.fullname, "C" as flag'));
$get_notifications = $get_projects->union($comments)
->whereRaw('updated_at > $last_check')
->orderBy('updated_at', 'desc')
->get();
Союзные работает нормально пока я не добавлю этот последний оператор whereRaw. С добавлением оператора я получаю ошибку синтаксиса SQL/Access (# 42000). Я думаю, что у него есть что-то, что можно было бы с помощью plucking update_at для сравнения. Есть идеи? Заранее спасибо!
Edit: Вот код ошибки
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '15:09:06) union (select project_comments.updated_at, requests.id as request_id, ' at line 1 (SQL: (select requests.updated_at, requests.id as request_id, requests.request_name, "" as fullname, "P" as flag from `requests` inner join `notifications` on `notifications`.`notif_project_id` = `requests`.`id` where `notif_user_id` = 1 and requests.updated_at > requests.created_at and requests.updated_at > 2015-07-29 15:09:06) union (select project_comments.updated_at, requests.id as request_id, requests.request_name, users.fullname, "C" as flag from `project_comments` left join `users` on `comment_user_id` = `users`.`id` left join `requests` on `comment_project_id` = `requests`.`id`) order by `updated_at` desc)
Вам может понадобиться сделать '-> whereRaw («updated_at> $ last_check»)', потому что нужно двойные кавычки, чтобы получить $ last_check быть расширенной – RiggsFolly
@RiggsFolly Неа, просто попытался, что и это не сработало , Все еще получите ошибку. – Vikram
положил whereRaw предложение для заказа – user4621032