Laravel - Views - Passing Data To Views

As you saw in the previous examples, you may pass an array of data to views to make that data available to the view:

    
    return view('greetings', ['name' => 'Victoria']);
	

When passing information in this manner, the data should be an array with key / value pairs. After providing data to a view, you can then access each value within your view using the data's keys, such as <?php echo $name; ?>.

As an alternative to passing a complete array of data to the view helper function, you may use the with method to add individual pieces of data to the view. The with method returns an instance of the view object so that you can continue chaining methods before returning the view:

    
    return view('greeting')
                ->with('name', 'Victoria')
                ->with('occupation', 'Astronaut');