Skip to content
Advertisement

laravel compact() and ->with()

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

JavaScript

This allows me to generate a view of arrays for fixtures, teams and selections as expected.

However,

JavaScript

does not allow the view to be generated properly. I can still echo out the arrays and I get the expected results but the view does not render once it arrives at the selections section.

It’s oké, because I have it working with the ->with() syntax but just an odd one.

Thanks. DS

Advertisement

Answer

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

JavaScript

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:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement