2017-07-25 36 views
0

我正在学larasts.com上的幼虫和关于视频,在关于布局和结构的讲座10中,我正在尝试@include,但它不起作用。@include在Laravel5.4中不工作

下面是我的文件:

/views/layout.blade.php

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> 
    <meta name="description" content=""> 
    <meta name="author" content=""> 
    <link rel="icon" href="../../favicon.ico"> 

    <title>Album example for Bootstrap</title> 

    <!-- Bootstrap core CSS --> 

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous"> 

    <!-- Custom styles for this template --> 
    <link href=" {{ URL::asset('css/album.css') }}" rel="stylesheet" > 
    </head> 

    <body> 

    <div class="collapse bg-inverse" id="navbarHeader"> 
     <div class="container"> 
     <div class="row"> 
      <div class="col-sm-8 py-4"> 
      <h4 class="text-white">About</h4> 
      <p class="text-muted">Add some information about the album below, the author, or any other background context. Make it a few sentences long so folks can pick up some informative tidbits. Then, link them off to some social networking sites or contact information.</p> 
      </div> 
      <div class="col-sm-4 py-4"> 
      <h4 class="text-white">Contact</h4> 
      <ul class="list-unstyled"> 
       <li><a href="#" class="text-white">Follow on Twitter</a></li> 
       <li><a href="#" class="text-white">Like on Facebook</a></li> 
       <li><a href="#" class="text-white">Email me</a></li> 
      </ul> 
      </div> 
     </div> 
     </div> 
    </div> 

    @inlcude('layouts.nav') <!-- This is not working --> 

    <section class="jumbotron text-center"> 
     <div class="container"> 
     <h1 class="jumbotron-heading">Album example</h1> 
     <p class="lead text-muted">Something short and leading about the collection below—its contents, the creator, etc. Make it short and sweet, but not too short so folks don't simply skip over it entirely.</p> 
     <p> 
      <a href="#" class="btn btn-primary">Main call to action</a> 
      <a href="#" class="btn btn-secondary">Secondary action</a> 
     </p> 
     </div> 
    </section> 

    <div class="album text-muted"> 
     <div class="container"> 

     <div class="row"> 
      <div class="card"> 
      <img data-src="holder.js/100px280/thumb" alt="Card image cap"> 
      <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 
      </div> 
      <div class="card"> 
      <img data-src="holder.js/100px280/thumb" alt="Card image cap"> 
      <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 
      </div> 
      <div class="card"> 
      <img data-src="holder.js/100px280/thumb" alt="Card image cap"> 
      <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 
      </div> 

      <div class="card"> 
      <img data-src="holder.js/100px280/thumb" alt="Card image cap"> 
      <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 
      </div> 
      <div class="card"> 
      <img data-src="holder.js/100px280/thumb" alt="Card image cap"> 
      <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 
      </div> 
      <div class="card"> 
      <img data-src="holder.js/100px280/thumb" alt="Card image cap"> 
      <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 
      </div> 

      <div class="card"> 
      <img data-src="holder.js/100px280/thumb" alt="Card image cap"> 
      <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 
      </div> 
      <div class="card"> 
      <img data-src="holder.js/100px280/thumb" alt="Card image cap"> 
      <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 
      </div> 
      <div class="card"> 
      <img data-src="holder.js/100px280/thumb" alt="Card image cap"> 
      <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> 
      </div> 
     </div> 

     </div> 
    </div> 

    <footer class="text-muted"> 
     <div class="container"> 
     <p class="float-right"> 
      <a href="#">Back to top</a> 
     </p> 
     <p>Album example is &copy; Bootstrap, but please download and customize it for yourself!</p> 
     <p>New to Bootstrap? <a href="../../">Visit the homepage</a> or read our <a href="../../getting-started/">getting started guide</a>.</p> 
     </div> 
    </footer> 

    </body> 
</html> 

/views/layouts/nav.blade.php

<div class="navbar navbar-inverse bg-inverse"> 
     <div class="container d-flex justify-content-between"> 
     <a href="#" class="navbar-brand">Album</a> 
     <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarHeader" aria-controls="navbarHeader" aria-expanded="false" aria-label="Toggle navigation"> 
      <span class="navbar-toggler-icon"></span> 
     </button> 
     </div> 
    </div> 

/views/posts/index.blade.php

@extends('layout') 

路线是正确设置:

Route::get('/','[email protected]'); 
+0

尝试'@extends(“views.layout”)' –

+0

您的意思是在'views/layout.blade.php'中写'@include('layouts.nav')'而不是'@inlcude('layouts.nav')'? –

+0

@OluwafemiSule:/views/layout.blade.php中的@include('layouts.nav')不起作用 –

回答

1

这是因为该文件是不是在应用程序/视图目录。

当您致电@include('layouts.nav')时,刀片会自动在应用程序/视图目录中查找具有该名称的任何文件。

+0

谢谢你指出,是的,这是没有包括文件的原因,挖掘更多后,我得到了正确的方式做到这一点,构成一样的答案。 –

+0

好吧,很酷,很高兴我可以帮助 –

0

刀片会在/app/config/view.phppaths阵列中的文件,再添加一个资源路径的伎俩如下:

'paths' => [ 
     resource_path('views'), 
     resource_path('/../views/layouts') 
    ], 
+0

是啊这就是我想挖掘的想法,但不知道同一问题, –

+0

@satyampathak:是的,上述工作非常好。 –