skip to Main Content
public function getWithdraws(Request $request)
{
$data = Withdraw::where(['status' => 0])->latest('id')->paginate(10);
foreach ($data->items() as $key) {
$user = User::where(['id' => $key->user_id])->first();
$key->name = $user->name;
$key->balance = $user->balance;
$key->verified = $user->verified;
}
return response(['success' => $data]);
}

I have such a part of the code, this function outputs all the necessary records with status 0 in the database , how do I make sure that all records with statuses 0 and 4 are output ?

Thank you in advance for the answer

I tried to write comma-separated

2

Answers


  1. Chosen as BEST ANSWER

    Figured it out, I arranged the code this way

    $data = Withdraw::where(['status' => 0])->orWhere(['status' => 4])->latest('id')- 
    >paginate(10);
    

  2. To retrieve records with statuses 0 and 4, you can modify the where clause in your query using the whereIn method. The whereIn method allows you to specify an array of values for a particular column, and it will retrieve records that have any of those specified values.

    Here’s how you can modify your function to fetch records with statuses 0 and 4:

    public function getWithdraws(Request $request)
    {
        $data = Withdraw::whereIn('status', [0, 4])->latest('id')->paginate(10);
        foreach ($data->items() as $key) {
            $user = User::where(['id' => $key->user_id])->first();
            $key->name = $user->name;
            $key->balance = $user->balance;
            $key->verified = $user->verified;
        }
        return response(['success' => $data]);
    }
    

    In the updated code, the whereIn method is used to retrieve records with statuses 0 and 4. The rest of the code remains the same, and the function will now return all the necessary records with statuses 0 and 4 from the database.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search