How to Include one blade to another blade file with content in Laravel

Laravel blade include file with content example; In this tutorial you will learn How to Include one blade to another blade file with content in Laravel. This tutorial will gives you simple example of include a sub-view in Blade templates in Laravel.

laravel provide @include directive to include sub view inside blade file. We will show how to include blade tempate in another file? Let’s see the below example to include child (included) file to parent blade file.

Main Default File:

Suppose we have an index default main file something like this


<!DOCTYPE html>
    <link href="//" rel="stylesheet">
<div class="container">
    <h1>Product List</h1>
    <table class="table table-bordered">
        @foreach ($products as $product)
            @include('products.details', ['product' => $product])

Included File:

Here the included file which will show the table recrods;


    <td>{{ $product->id }}</td>
    <td>{{ $product->name }}</td>
    <td>{{ $product->detail }}</td>

Controller File Code:

Here is the controller file where from we are sending the array content data.



namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Product;

class ProductController extends Controller
    public function index()
        $protucts = Product::all();
        return view('products.index', compact('protucts'));


Hope its work for you.

Leave a Comment