0

I developed following code,

public function getInCalls($sip_id){  

      $resultsTotalInCalls =  DB::table('xxxx')
    ->whereDate('created', '=', date('Y-m-d'))
    ->where(function ($query) {

    $query->where([
    ['event', '=', 'ENTERQUEUE'],
    ['agent', '=', $sip_id]

]);
    })

    ->get();  

     $numberofInCalls =  count($resultsTotalInCalls);   

     return $numberofInCalls;

}

But I got undefined index $sip_id in ['agent', '=', $sip_id] line. How to pass $sip_id in to function? I have no idea.

4 Answers 4

1

Closures needs importing variables from outside.

->where(function ($query) use ($sip_id) {
Sign up to request clarification or add additional context in comments.

Comments

0

You should try this:

public function getInCalls($sip_id){  

          $resultsTotalInCalls =  DB::table('xxxx')
        ->whereDate('created', '=', date('Y-m-d'))
        ->where(function ($query) use($sip_id) {

        $query->where([
        ['event', '=', 'ENTERQUEUE'],
        ['agent', '=', $sip_id]

    ]);
        })

        ->get();  

         $numberofInCalls =  count($resultsTotalInCalls);   

         return $numberofInCalls;

    }

Comments

0

If you'd rather use closures then you can import variable to the current scope (the use keyword):

https://stackoverflow.com/a/11086796/3520693

public function getInCalls($sip_id){

    $resultsTotalInCalls =  DB::table('xxxx')
        ->whereDate('created', '=', date('Y-m-d'))
        ->where(function ($query) use ($sip_id) {

            $query->where([
                ['event', '=', 'ENTERQUEUE'],
                ['agent', '=', $sip_id]

            ]);
        })

        ->get();

    $numberofInCalls =  count($resultsTotalInCalls);

    return $numberofInCalls;

}

Comments

0
public function getInCalls($sip_id){
    $resultsTotalInCalls =  DB::table('abc')
        ->whereDate('created', '=', date('Y-m-d'))
        ->where(function ($query) use ($sip_id) {
            $query->where([ ['event', '=', 'ENTERQUEUE'], ['agent', '=', $sip_id]  ]); 
        })
        ->get();  
    $numberofInCalls =  count($resultsTotalInCalls);
    return $numberofInCalls;  
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.