By Hardik Savani February 8, 2021 Category : LaravelPlayUnmuteLoaded: 1.17%FullscreenHello all! In this article, we will talk about how to create custom blade directive in laravel. you'll learn laravel custom blade directives. We will use laravel create custom blade directives. we will help you to give example of custom blade directive laravel.
what is directive in laravel blade template. you can create your own @var, @if, @case directive that we help you to avoid write so many time same code and you can reuse it easily.
In this post, i will give you simple example of creating custom blade directives in laravel and you can easily use with laravel 6, laravel 7, laravel 8 and laravel 9 app. we will create @nl2br blade directive and use it with example. we almost need nl2br() for textarea value displcy. you can see bellow layout.
Preview:
Step 1: Create Custom Blade Directive
in app service provide file you have to declare custom blade directive. so let's add code as bellow:
app/Providers/AppServiceProvider.php
Step 2: Create Route
now we will create one route for example how to use custom directives in laravel blade. let's add as bellow: