Laravel: i can't send more then 2 variables from controller to a view

前端 未结 1 884
死守一世寂寞
死守一世寂寞 2020-12-02 03:11

So i am trying to send some query from the controller to a view but when try use the third variable it says:

Undefined variable: type(View:)

相关标签:
1条回答
  • 2020-12-02 03:45

    You should return one array :

    return view('dashboard',['doc'=>$doc,'user'=>$user,'type'=>$type]);
    

    There is other ways such us :

    return view('dashboard', array('doc'=>$doc,'user'=>$user,'type'=>$type));
    
    return view('dashboard', compact('doc','user','type'));
    
    return view('dashboard')
                ->with('doc', $doc)
                ->with('user', $user)
                ->with('type', $type);
    
    return view('dashboard')            //using laravel Magic method.
                ->withDoc($doc)
                ->withUser($user)
                ->withType($type);
    
    0 讨论(0)
提交回复
热议问题