我在一页上使用两个@yield作为主要内容,在第二页上使用navbar,但是navbar根本没有显示,我是laravel的新手,一定是用错误的方式学习了一些概念。 该项目遵循以下文件夹结构
views /
component / navbar.blade.php
layouts / main.blade.php
reviewer / reviewer.blade.php
web.php
Route::resource('reviewer', 'ReviewerController');
ReviewerController.php
public function index(){
$title = "All Project";
$projects = session('projects');
return view('reviewer.index', compact(['projects','title']));
}
main.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace(' _', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
@yield('navbar')
@yield('conteudo')
</body>
</html>
reviewer.blade.php
@extends('layouts.main')
@section('conteudo')
<h3> {{$title}} <h3>
<ul>
@foreach( $projects as $p )
<li> {{ $p['id'] }} | {{ $p['name'] }} | {{ $p['appraiser']}} | {{ $p['student'] }} </li>
@endforeach
</ul>
@endsection
navbar.blade.php
@extends('layouts.main')
@section('navbar')
<div id='menu'>
<ul>
<li><a href="#">Início</a></li>
<li><a href="#">Edital</a></li>
<li><a href="#">Resultados</a></li>
<li><a href="#">Bem vindo user</a></li>
</ul>
</div>
@endsection
答案 0 :(得分:2)
尝试这个main.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace(' _', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
@include(' component.navbar')
@yield('conteudo')
</body>
</html>
reviewer.blade.php
@extends('layouts.main')
@section('conteudo')
<h3> {{$title}} <h3>
<ul>
@foreach( $projects as $p )
<li> {{ $p['id'] }} | {{ $p['name'] }} | {{ $p['appraiser']}} | {{ $p['student'] }} </li>
@endforeach
</ul>
@endsection
navbar.blade.php
<div id='menu'>
<ul>
<li><a href="#">Início</a></li>
<li><a href="#">Edital</a></li>
<li><a href="#">Resultados</a></li>
<li><a href="#">Bem vindo user</a></li>
</ul>
</div>
ReviewController.php
public function index(){
$title = "All Project";
$projects = session('projects');
return view('reviewer.reviewer', compact(['projects','title']));
}