Answer the question
In order to leave comments, you need to log in
How to build query to get data from DB with Elequent ORM?
How to write a query for a selection, for example, through if I can select the records that I need, but at the same time I then get all the records from the database and compare and send the
necessary ones through a loop.
$user = User::find($user_id);
$messages = Message::where('active', true)->get();
if($message->referrer == true || $message->referrer == false && $user->referrer_1_id == null){
Answer the question
In order to leave comments, you need to log in
https://laravel.com/docs/9.x/queries#conditional-c...
something like
Message::where('active', true)
->when($user->referrer_1_id !== null, function ($query, $userReferrerIsNotNull) {
$query->where('referrer ', true);
})->get()
I don't know what kind of perversion to use when.
like this, you can configure it as you like and just do pass the request anywhere in the variable.
$user = User::find($user_id);
$messagesQuery = Message::where('active', true);
if($message->referrer == true || ($message->referrer == false && $user->referrer_1_id == null)){
$messagesQuery->where(....);
}
$messages = $messagesQuery->get()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question