Laravel Include Blade File with Data Example

In this tutorial i explain laravel include blade file with data example. Also i will like to show you laravel blade include file with data. You can understand of include file with data in laravel blade. I simple way to explain how to include file with data in laravel view.

We almost require to use include blade file inside another blade file. As specially when you require 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.

Read Also :  Laravel Carbon Add Seconds Example

You can easily include blade file with data in your laravel 6, laravel 7 and laravel 8 app. In this example i pass alert message with laravel include blade file.

Laravel Include Blade File with Data Example

<?php

use Illuminate\Support\Facades\Route;

Route::view("/", "index");

Create index.php blade file.

<!DOCTYPE html>
<html>
<head>
    <title>Laravel Include Blade File with Data Example - Web-tuts.com</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('alert', ['type' => 'success', 'content' => 'This is success alert'])
   
    @include('alert', ['type' => 'danger', 'content' => 'This is error alert'])
   
    @include('alert', ['type' => 'info', 'content' => 'This is info alert'])
   
</div>
  
</body>
</html>

Create alert.php blade file.

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

I hope you understand laravel include blade file with data.