A collection of programming & webdesign
Laravel passing several variables to view

There are several ways of passing multiple variables to a view in Laravel:

1. Using with()

return view('articles.single-article')
            ->with('article', $article)
            ->with('subcategories', $subcategories)
            ->with('subcategory', $subcategory);
        }

2. Using an array

return view('single-article', [
            'article'=>$article,
            'subcategories'=>$subcategories
        ]);

3. Using compact()

return view('single-article', compact([
                'article',
                'subcategories'
            ]
        ));