rematnarab rematnarab - 1 month ago 8
PHP Question

Laravel layouts not working

I am trying something really simple and can not get it to work.
I have 2 pages. admin.blade.php and left.blade.php
I am trying to use admin page as the master page. and include date from left.blade.php

The admin pages print only "test" as the result and includes nothing from left.admin.php.
I can`t see what is wrong. Thanks in advance

File structure is

-- resources
--views
*admin.blade.php
*left.blade.php


left.blade.php

@extends('admin')

@section('content')
baran
@stop


admin.blade.php

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title> @yield('title')</title>
</head>
<body>
<?php
// put your code here
?>

@yield('content')

test
<div id='footer'>
@yield('footer')
</div>
</body>
</html>


route command in web.php is

Route::get('/admin', function () {
return view('admin');
});

Answer

If you want to include date from left.blade.php you should use @include() directive in admin.blade.php:

@include('left')

If your main content is in left.blade.php and you're using admin.blade.php as layout only then change you route:

Route::get('/admin', function () {
    return view('left');
});