Laravel Include Blade File with Data Example

By Hardik Savani | March 4, 2021 | Category : Laravel


Hi Dev,

This post will give you example of laravel include blade file with data. i would like to show you laravel blade include file with data. you can understand a concept of include file with data in laravel blade. i explained simply about how to include file with data in laravel view.

We almost need to use include blade file inside another blade file. as specially when you need same design and code use again and again then you will create conman file and call it each tile. laravel provide @include directive to include sub view inside blade file.

you can easily include blade file with data in your laravel 6, laravel 7 and laravel 8 app. let's see simple example bellow:

resources/views/products/index.blade.php

<!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>

now you can run and see layout as like bellow:

i hope it can help you...



Tags : Laravel


Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: