How to Include Blade File with Data in Laravel?

Hi Dev team,
Today in this post I will give you a simple and good example of laravel include blade file with data. I would like to show you how to laravel blade include file with data?

From here you can easily understand about a concept of add file with data in laravel blade.

So now I will explaine it simply about how to include file with data in laravel view by using larvael application.

We almost need to use another include blade file inside another blade file. As specially when we need to re-use same design and code again and again. Then that time we can create a conman file and call it each tile. laravel provide us @include directive to include sub view inside on blade file.

We can easily extend blade file with data in our laravel 5.*, laravel 6, laravel 7 and laravel 8 any application. let’s start and see a simple example in bellow:

Read Also : Laravel One to Many Eloquent Relationship

<!DOCTYPE html>
    <link href="//" rel="stylesheet">
<div class="container">
    <h1>Alert List</h1>
    @include('products.alert', ['type' => 'success', 'content' => 'This is success alert'])
    @include('products.alert', ['type' => 'danger', 'content' => 'This is error'])
    @include('products.alert', ['type' => 'info', 'content' => 'This is info'])


<div class="alert alert-{{$type}}">
    {{ $content }}

Read Also : Vue JS Get Array Length Or Object Length

You can try by your self. Thanks for read this, I hope it will you. You can also follow us on Facebook.


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →