0

Can any one tell me why i am getting error for the following code.

public function postFormfilehandellerpre(){
        $event = Input::get('event');

        if($event =="Rescom Summit Bangalore 2015")
        $qid1 = "3124";

        $users = User::where('event','=',$event)->orderby('name')->with(array('answer'=>function($q){
            $q->where('question_id','=',$qid1)->orWhere('question_id','=',$qid1+1);
        }))->get();


        return Redirect::to('admin/formfilehandellerpre')->with(array('liusers'=>$users,'liev'=>$event));
    }

ERROR

Undefined variable: qid1

Then i tried to pass the $qid inside the function like this

$users = User::where('event','=',$event)->orderby('name')->with(array('answer'=>function($q,$qid1){
            $q->where('question_id','=',$qid1)->orWhere('question_id','=',$qid1+1);
        }))->get();

ERROR

Missing argument 2 for AdminController::{closure}()
3
  • I think it should be 'answer' => function() use($q, $qid1) { Commented Aug 27, 2015 at 7:16
  • @CharlotteDunois oh yeah right let me try this , Commented Aug 27, 2015 at 7:16
  • Yes it works It just didnt pass my mind :(, You can post as an answer I will accept it thanks Commented Aug 27, 2015 at 7:17

1 Answer 1

2

I don't use laravel but if you expect them as parameter laravel doesn't know that, which is why you have to use

function() use($expected, $parameters) {

In your case it is

function() use($q, $qid1) {
Sign up to request clarification or add additional context in comments.

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.