$projects = Project::whereHas('logbook', function ($q) use ($user) {
$q->join(DB::raw('(SELECT project_id, count(*) FROM logbook WHERE state_id = 13 AND event_id = 20 AND consider = 1 HAVING count(*) < 2) message'), 'logbook.project_id', '=', 'message.project_id')
->whereHas('user', function ($q) use ($user) {
$q->whereIn('id', [$user->id]);
})->whereHas('state', function ($q) {
$q->whereIn('name', ['state3']);
})->whereHas('event', function ($q) {
$q->whereIn('name', ['took']);
})->where('consider', true);
})->get();