Laravel Blade Directives
Laravel Blade Directives are the functions of Laravel’s templating engine that are basically a piece of code that covers the complex yet common and repetitive code written in PHP. Many of these directives are used while working on blade files but some of the unused but useful blade directives are mentioned below, which will help you in making code repetition free and more like an MVC’s view file.
1. @php |
|
---|---|
WITHOUT DIRECTIVE
<?php |
WITH DIRECTIVE
@php |
2. @each |
|
WITHOUT @each
@foreach($posts as $post) |
WITH @each
@each(‘pages.november_posts’,$post, ‘post’) |
3. @forelse |
|
WITHOUT @forelse
@if($post->count() > 0) |
WITH @forelse
@forelse($posts as $post) |
4. @isset |
|
WITHOUT @isset
@if(isset($posts)) |
WITH @isset
@isset($posts) |
5. @empty |
|
WITHOUT @empty
@if(isset($posts)) |
WITH @empty
@empty($posts) |