laravel compact() and ->with()

后端 未结 7 1442
梦谈多话
梦谈多话 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 07:59

    You can pass array of variables to the compact as an arguement eg:

    return view('yourView', compact(['var1','var2',....'varN']));
    

    in view: if var1 is an object you can use it something like this

    @foreach($var1 as $singleVar1)
        {{$singleVar1->property}}
    @endforeach
    

    incase of single variable you can simply

    {{$var2}}
    

    i have done this several times without any issues

提交回复
热议问题