Categories: Laravel Application, Laravel Framework - The PHP Framework For Web Artisans

4 Awesome Laravel Blade Directive To Use2 min read

4 awesome laravel blade directive
Reading Time: 2 minutes

Laravel Blade is a templating engine in Laravel which is very simple and yet way more pwerful to use. It which allows you to even use plain PHP code into your code file which most of the blade templating engine fails to do so. In  Laravel Blade, views are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application. And that’s the beauty of using the Laravel templating engine.

In this article i am going to tell you about the 4 awesome Laravel Blade Directive which you can use into your application and can simplify the process of developing of cool laravel application. So let’s begin

4 Awesome Laravel Blade Directive To Use

Blade uses .blade.php extension to begin with and is stored in the resources/views of the your installed Laravel application .

#1 – Check If User is authenticated

In the laravel we use the following code to check if the user is authenticated or not

// The user is authenticated.
   But in the Laravel Blade directive we can use something like this to avoid the above code.

//the user is authenticated

#2- Use Plain PHP in Your Blade View

To use the plain PHP in the Laravel blade we can use either something like this to begin with

//your php code goes here
   Isn’t it awesome to have been able to work with the plain PHP code in the Laravel Blade directive.

 Read More :- Laravel 5.6.30 [Security Release] Here’s What’s New !

#3 – View Based on the condition

View Based on the condition
View Based on the condition

Conditionally including a view based on a condition is useful when you only want to add content based on logic like an authenticated user.

You could write this using an @if condition:


# 4- Render JSON In Laravel Blade

Earlier to encode the JSON reponse from your API call or from your code you to manually call the JSON code However, instead of manually calling json_encode, you may use the @json Blade directive:

You can learn about these and other useful tricks in the official Blade documentation for improving your frontend templating in a Laravel project.

Happy Coding !

All Rights Reserved @ Techanical-Atom
%d bloggers like this: