Some cool features of laravel

Laravel has a lot of helpers functions and handy tips already available for you to make your application and their logic little bit clearer and understandable. Well here are some functions and features which are hidden in laravel documentation and some of them not documented at all.

1. Cascading Views

It is not documented in laravel. Cascading views is one of the cool features in laravel. Cascading views are extremely useful when creating or developing extendable theming system. Just like wordpress theme , we can make different themes for our laravel application if we play around with it, isn’t it cool ?

Let’s say we have this following folder structure :

return View::make(‘theme::user.index’); 

Above syntax will look for theme/default/views directory , if it can’t find the the view, then it will fallback to app/views. To use this amazing feature , we must register our own namespace with the two location one for the themes and other for fallback views.

2. Message Bag

Illuminate\Support\MessageBag , we have been using this for a while now. Do you know how we get all the errors on our views so easily ? If yes great, if not then  you’re using laravel’s built in validators sometime custom or something package, but normally we use laravel built in error validators, if this is the case than, hear me out MessageBag will contain all of your validation errors. for an instance , $errors variable is available in your each view either containing empty messageBag instance or with the validation errors.

3. Blade Directive

Blade is the simple, yet powerful templating engine provided with Laravel. With features of template inheritance blade is awesome. With @section , @yield, @extends ,@parent directive’s laravel blade is pretty powerful. This is not all , we have many other directive’s too . Let’s look at some of them .

@auth

Do you remember when we used to do something like below to check if user is authenticated or not using a facade ..

Now, we can do something more easy like :

This is easy and more clean way to do it. well you can use any way.

@guest

We have guest directives too. If you’re following along the article, then you might have guessed already what this directive will do. This will simply tell us if a user is guest or not.

This is how we can use it.

4. Laravel Config files

This is also one of the cool features of laravel. Using a config file, we can make configurable system. By just setting some array values in a file, we can make your application or packages configurable. Let’s jump in to the topic where we create a config file and use them in a real world application, sounds hard but laravel always tends to make easy for developer to create or develop anything.

You can create config file in laravel config folder, where there are many other config files like app.php, config.php and many other. Let’s just create our own config file, you can name it anything as per your requirement. Suppose, you created yourname.php config file. The file will contain :

Now how do i get the value’s set with a key username or site_url or description ?

Laravel has a helper file for that too . Well you can use facade too 🙂 .

yourname will be the config file name you created and username is the key. It’s easy right. This is just an example you can use it with multi-dimensional arrays too.

These are some of the features only, there are many out there which makes laravel amazing . We will soon update more features of laravel.

Sharing is caring!

Related Post