laravel compact() and ->with()

后端 未结 7 1398
梦谈多话
梦谈多话 2020-11-30 07:17

I have a piece of code and I\'m trying to find out why one variation works and the other doesn\'t.

return View::make(\'gameworlds.mygame\', compact(\'fixture         


        
相关标签:
7条回答
  • 2020-11-30 08:22

    The View::make function takes 3 arguments which according to the documentation are:

    public View make(string $view, array $data = array(), array $mergeData = array())
    

    In your case, the compact('selections') is a 4th argument. It doesn't pass to the view and laravel throws an exception.

    On the other hand, you can use with() as many time as you like. Thus, this will work:

    return View::make('gameworlds.mygame')
    
    ->with(compact('fixtures'))
    
    ->with(compact('teams'))
    
    ->with(compact('selections'));
    
    0 讨论(0)
提交回复
热议问题