ItSolutionStuff.com

Laravel Blade Include File Example

By Hardik Savani • April 16, 2024
Laravel

Hi Dev,

This simple article demonstrates of laravel blade include file example. i would like to show you how to include sub view in blade laravel. This tutorial will give you simple example of laravel include file in blade. step by step explain laravel include php file in blade.

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 in your laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 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>Product List</h1>

<table class="table table-bordered">

<tr>

<th>No</th>

<th>Name</th>

<th>Details</th>

</tr>

@foreach ($products as $product)

@include('products.product')

@endforeach

</table>

</div>

</body>

</html>

resources/views/products/product.blade.php

<tr>

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

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

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

</tr>

now you can run and see layout as like bellow:

i hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel Blade Empty Directive Example

Read Now →

Laravel Blade Isset Else Example

Read Now →

Laravel Blade Foreach Loop Example

Read Now →

Laravel Blade Switch Case Statement Example

Read Now →

Laravel Blade If Multiple Conditions Example

Read Now →

Laravel Blade If Condition Example

Read Now →

Laravel nl2br Blade Directive Example

Read Now →

How to Create Custom Blade Directive in Laravel?

Read Now →

Laravel Blade Check If Variable is Set or Not Example

Read Now →

How to Write PHP Code in Laravel Blade?

Read Now →