merhaba arkadaşlar basit bir search işlemi için paket vs kullanmak istemedim eloquent ile çözerim dedim ancak ya veri gelmiyor yada gelen veri yanlış oluyor bazı orWhere yada whereler devreye girmiyor anlamadım sorun nedir. yapı olarak mantıklı ve doğru olduğunu düşünüyorum 😃
aşağıdaki wherehasmorph ve with içindeki relations bağlantıosını kaldırıp receiver message or where has i wherehas yapınca userlerı vs doğru getiriyor anlamadım sorunu
$notification->where(function ($q) {
$q->where('sender_id', Auth::id())->where('sender_is_active', true)
->orWhere('receiver_id', Auth::id())->where('receiver_is_active', true);
})->whereHas('sender_message', function ($q) {
$q->where('main_type', 4);
})->orWhereHas('receiver_message', function ($q) {
$q->where('main_type', 4);
})->whereHas('senderUser', function ($q) use ($search) {
$q->where('username', 'ilike', '%' . $search . '%');
})->orWhereHas('receiverUser', function ($q) use ($search) {
$q->where('username', 'ilike', '%' . $search . '%');
})->whereHasMorph('notifiable', [Complaint::class], function (Builder $query) use ($search) {
$query->whereHasMorph('complainable', [Booth::class, Profile::class], function (Builder $query, $type) use ($search) {
if ($type === Booth::class) {
$query->where('name', 'ilike', '%' . $search . '%');
} else if ($type === Profile::class) {
$query->whereHas('user', function ($q) use ($search) {
$q->where('username', 'ilike', '%' . $search . '%');
});
}
});
})->with(['senderUser', 'receiverUser', 'notifiable' => function ($q) {
$q->with(['complainable' => function (MorphTo $morphTo) {
$morphTo->morphWith([
Booth::class => ['hall'],
Profile::class => ['user'],
]);
}]);
}, 'sender_message' => function ($q) {
$q->with('notification_message_types');
}, 'receiver_message' => function ($q) {
$q->with('notification_message_types');
}]);
$skipCount = 0;
$takeCount = 20;
$countComplaints = $notification->count();
$searched = $notification->skip($skipCount + (($currentPage - 1) * $takeCount))->take($takeCount)->get();