29.07.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Views<br />

• Basic Usage A> - Passing Data To Views A> - Sharing Data With All Views<br />

• View Composers<br />

Basic Usage<br />

Views contain the HTML served by your application and separate your controller / application logic<br />

from your presentation logic. Views are stored in the resources/views directory.<br />

A simple view might look something like this:<br />

.<br />

1 <br />

2<br />

3 <br />

4 <br />

5 Hello, <br />

6 <br />

7 <br />

Since this view is stored at resources/views/greeting.php, we may return it using the global view<br />

helper function like so:<br />

.<br />

1 Route::get('/', function () {<br />

2 return view('greeting', ['name' => 'James']);<br />

3 });<br />

As you can see, the first argument passed to the view helper corresponds to the name of the view<br />

file in the resources/views directory. The second argument passed to helper is an array of data<br />

that should be made available to the view. In this case, we are passing the name variable, which is<br />

displayed in the view by simply executing echo on the variable.<br />

Of course, views may also be nested within sub-directories of the resources/views directory.<br />

“Dot” notation may be used to reference nested views. For example, if your view is stored at<br />

resources/views/admin/profile.php, you may reference it like so:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!