11.08.2017 Views

codebright

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Responses 60<br />

13 <br />

14 This is the perfect response!<br />

15 <br />

16 ';<br />

17 });<br />

Awesome! Now you see the power and grace of Laravel… just kidding. We don’t want to serve<br />

HTML this way. Embedding logic would get annoying and, more importantly, it’s just plain wrong!<br />

Luckily for us, Laravel has a number of Response objects that make returning a meaningful reply a<br />

whole lot easier. Let’s check out the View response since that’s the most exciting one!<br />

Views<br />

Views are the visual part of your application. Within the Model View Controller pattern they make<br />

up the View portion. That’s why they are called views. It’s not rocket science. Rocket science will be<br />

covered in a later chapter.<br />

A view is just a plain text template that can be returned to the browser, though it’s likely that<br />

your views will contain HTML. Views use the .php extension and are normally located within the<br />

app/views directory. This means that PHP code can also be parsed within your views. Let’s just create<br />

a very simple view for now.<br />

1 <br />

2<br />

3 <br />

4 <br />

5 <br />

6 <br />

7 Views!<br />

8 <br />

9 <br />

10 Oh yeah! VIEWS!<br />

11 <br />

12 <br />

Great! A tiny bit of HTML stored in app/views/simple.php. Now let’s make a view.<br />

Didn’t we just do that?<br />

Haha! Yes you did little one, but I didn’t mean ‘Let’s make another view file.’. Instead let’s make()<br />

a new view response object based upon the view file we just created. The files representing views<br />

can be called templates. This may help you distinguish between the View objects and the HTML<br />

templates.

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

Saved successfully!

Ooh no, something went wrong!