#### RESTful Controllers

Laravel's RESTful controllers makes it easy to add RESTful responses to any Laravel controller. This makes it easy to create, for instance, a RESTful API. To do so, simply add the \$restful flag to your controller:

We'll dive into all of these cool features in future tutorials, but, for now, let's update the Home controller. We'll need to add an an action_about method, since we created the http://instapics.com/about route to direct to this method. Open application/controllers/home.php, and update it, like so:

We append action_ to all action methods in our controllers (e.g. action_about). This signals to Laravel that these actions are viewable on the website. Any other methods, which don't have the action_ prefix, will not be publicly accessible.

## Step 4. Create your first Laravel View with the Blade Templating Engine

Laravel supports two ways to generate views for an application:

• PHP-based Views - these are views that make use of PHP as a templating language.
• Blade-based Views - these are views that make use of Laravel's built-in templating engine, called Blade.

The Blade Templating Engine is a templating framework that, similar to how the Smarty Templating Engine works, makes use of customized tags and functions to allow for better separation of presentation logic and application code.

For the sake of simplicity, we'll be utilizing the Blade Templating Engine, as opposed to the PHP-based views.

All view files that will make use of the Blade Templating Engine needs to have a .blade.php extension. This tells Laravel to use the engine on the view file.

First, let's create a general purpose layout that we'll use for all our views. Create the application/views/layouts folder, and inside, create a file, named main.blade.php:

Now that we have our main layout, let's update the index file. Open application/views/home/index.blade.php and update it:

Let's review our view files. In the main layout template, we make use of three functions:

• The Assets manager (Assets::styles(), Assets::scripts())
• The @section Blade function (with @yield_section)
• And the @yield Blade function

### Managing Assets

Laravel provides a robust way to load CSS and JS files, via its Assets management functionality. The syntax for adding an asset is Assets::add('[asset name]', '[relative url from the public folder'], '[name of dependency, array of dependencies if multiple]'). The Assets manager also provides support for asset dependencies, which are used to tell Laravel to load the dependency first, before loading the asset.

We'll need to register our assets so that the view files will be able to use them. Open application/controllers/base.php, and add the following code:

By doing this, we make it easier to add, remove or update any assets that we need. We put it inside the Base controller's __construct() method to add the assets to all our controllers. To take advantage of this within a view, we simply call Assets::styles() for CSS files, and Assets::scripts() for the JS files in any view file. Laravel automatically determines what the asset type is, based on the file extension, and loads it with the appropriate asset group.

### @section (and @yield_section)

Sections let us inject content into the main layout from within a view. To define which part of our main layout is a section, we surround it with @section and @yield_section Blade tags.

In our main view file, we've marked the navigation items as a @section (called navigation). Looking now at the index view file, we append the <>About> navigation link to the navigation bar with the following code:

By calling the @parent function, we instruct the view file to inherit the contents of the original section from the main layout. If we were to remove the @parent function, like so:

Now, the index view file's navigation section will replace the main layout's navigation entirely. This makes the process of changing the main layout's HTML even more flexible.

### @yield

The @yield function is similar to the @section/@yield_section function, but, instead, lets the nested view fill the content entirely. In our index file, we have a @section('content') function that replaces @yield('content').

Now, let's try passing in some variables to our views. First, create a new view file in the application/views/home folder for the About page. Let's call it about.blade.php:

Back in the Home controller, update the action_about() method:

Reviewing our code, we see that, in the Home controller, we pass in an array of parameters. Right now, these are hardcoded values, but they can come from anywhere - for example, from a model or database. These are passed to the view file, where we make use of some Blade tags to render the parameters.

This lets us loop through the array in our parameters.

This is an if-statement. If we wanted to use an else, it would look like this:

This is the most basic Blade tag - it just echoes the variable we set.

Take note that, within most of the Blade tags, we use good 'ol PHP. This makes it easier to write the Blade tags, since we'll be able to use native PHP functions, like isset() or count(). There are also other Blade tags that I wasn't able to use here; you can learn more about them in the Blade documentation. Trust me, it's pretty easy!

## Conclusion

After reading this tutorial, we've learned:

• What Laravel is
• What makes Laravel different from other PHP frameworks
• How to setup Laravel
• How Laravel's Routing system works
• Some other features in Laravel's Routing system
• How to create your first Laravel Controller
• Some additional features with Laravel's Controllers
• How to create your first Laravel View
• How to use Laravel's Blade Templating Engine

Laravel is truly an amazing framework. It's fast, simple, elegant and so easy to use. It absolutely merits being considered as the framework to be used for your next project.

The Laravel category on Envato Market is growing fast, too. There's a wide selection of useful scripts to help you with your projects, whether you want to build an image-sharing communityadd avatar functionality, or much more.

Next in our Building Web Application from Scratch with Laravel series, we'll learn about one of Laravel's best features: the Eloquent ORM and Fluent Query Builder.

What do you think about Laravel? Are you considering using it for your next project? Let me know in the comments! And, if you're a Tuts+ member, stay tuned for our upcoming Laravel Essentials course!