skip to Main Content

enter image description here

hi, i’m trying to show users data whereNotIn on other table using kelas_id.
but i cant use kelas_id params in query function on DB:table.
please help, thank you so much

2

Answers


  1. Chosen as BEST ANSWER

    i have found the answer, u can solve this with add use ($diklat) after ($query)

    the code will be like this :

    $diklat = Diklat::where('id', $diklat_id)->first();
            $user = DB::table("users")->select('*')->whereNotIn('id', function ($query) use ($diklat) {
                $query->select('user_id')->from('diklat_details')->where('diklat_id', $diklat->id);
            })->where('users.role', 1)->get();
    

  2. The answer above is correct, this is due to the scope of the variables. The anonymous function can’t read the data $kelas_id because it’s scopes begins when is created.
    The solution is a use and the variable we want to use.

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