Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

costinecula's avatar

How laravel @extends work?

Hi everyone, I'm almost finish my own MVC framework, but I want to come with some updates like extends, but I'm no idea how to start honestly, have you any idea?

My framework if you are curious: https://necuframe.com

0 likes
1 reply
tigerjun's avatar

First i got a app.blade.php file

Inside this file i put this. I import all the file needed here.

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
</head>
<body>
	<div id="app">
		<main>
			<div class="container-fluid">
				@yield('content')
			</div>
		</main>
	</div>
</body>
</html>

You can see got a thing call @yield('content'). This is the location where i put content inside.

Than i got another file name index.blade.php

@extends('app')

@section('content')
	<h1>Content Here</h1>
@endsection

As you can see the @extend('app') is the my first file name. This will get all my html inside @section('content') and put inside the @yield('content') which located in my first file.

This is how i use it. The same header will compile to each file you open.

Mean you can open many index file with the same header. You no need to copy and paste the header again and again to each html file.

Please or to participate in this conversation.