How to Include Blade File with Data in Laravel?

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

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>
<html>
<head>
    <title></title>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
  
<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>
  
</body>
</html>

resources/views/products/alert.blade.php

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

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 code chef

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 code chef →