c9 上的 Laravel Blade 模板仅选择性地扩展到某些页面

Posted

技术标签:

【中文标题】c9 上的 Laravel Blade 模板仅选择性地扩展到某些页面【英文标题】:Laravel Blade template on c9 is only selectively extending to certain pages 【发布时间】:2019-04-01 17:54:56 【问题描述】:

我的刀片模板毫无问题地扩展到 index.blade.php,但根本没有扩展到位于子文件夹中的 create.blade.php。它只显示“创建用户”,没有别的。我目前正在使用 Laravel 5.2 和 PHP 5.5。

以下是我的 admin.blade.php,它是布局模板:

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Admin</title>

    <!-- Bootstrap Core CSS -->

    <link href="/css/app.css" rel="stylesheet" type="text/css">
    <link href="/css/libs.css" rel="stylesheet" type="text/css">

    <!--<link rel="stylesheet" href=" URL::asset('/css/app.css') ">-->
    <!--<link rel="stylesheet" href=" URL::asset('/css/libs.css') ">-->
    <!--<link rel="stylesheet" href=" URL::asset('/css/bootstrap.css') ">-->
    <!--<link href="asset('css/app.css')" rel="stylesheet">-->
    <!--<link href="asset('css/libs.css')" rel="stylesheet">-->
    <!--<link href="/css/blog-post.css" rel="stylesheet" type="text/css">-->
    <!--<link href="/css/bootstrap.css" rel="stylesheet" type="text/css">-->
    <!--<link href="/css/bootstrap.min.css" rel="stylesheet" type="text/css">-->
    <!--<link href="/css/font-awesome.css" rel="stylesheet" type="text/css">-->
    <!--<link href="/css/metisMenu.css" rel="stylesheet" type="text/css">-->
    <!--<link href="/css/sb-admin-2.css" rel="stylesheet" type="text/css">-->
    <!--<link href="/css/styles.css" rel="stylesheet" type="text/css">-->

    <!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.css">-->


    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body id="admin-page">

<div id="wrapper">

    <!-- Navigation -->
    <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">Home</a>
        </div>
        <!-- /.navbar-header -->



        <ul class="nav navbar-top-links navbar-right">


            <!-- /.dropdown -->
            <li class="dropdown">
                <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                    <i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
                </a>
                <ul class="dropdown-menu dropdown-user">
                    <li><a href="#"><i class="fa fa-user fa-fw"></i> User Profile</a>
                    </li>
                    <li><a href="#"><i class="fa fa-gear fa-fw"></i> Settings</a>
                    </li>
                    <li class="divider"></li>
                    <li><a href=" url('/logout') "><i class="fa fa-sign-out fa-fw"></i> Logout</a>
                    </li>
                </ul>
                <!-- /.dropdown-user -->
            </li>
            <!-- /.dropdown -->


        </ul>






        --<ul class="nav navbar-nav navbar-right">--
        --@if(auth()->guest())--
        --@if(!Request::is('auth/login'))--
        --<li><a href=" url('/auth/login') ">Login</a></li>--
        --@endif--
        --@if(!Request::is('auth/register'))--
        --<li><a href=" url('/auth/register') ">Register</a></li>--
        --@endif--
        --@else--
        --<li class="dropdown">--
        --<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> auth()->user()->name  <span class="caret"></span></a>--
        --<ul class="dropdown-menu" role="menu">--
        --<li><a href=" url('/auth/logout') ">Logout</a></li>--

        --<li><a href=" url('/admin/profile') /auth()->user()->id">Profile</a></li>--
        --</ul>--
        --</li>--
        --@endif--
        --</ul>--





        <div class="navbar-default sidebar" role="navigation">
            <div class="sidebar-nav navbar-collapse">
                <ul class="nav" id="side-menu">
                    <li class="sidebar-search">
                        <div class="input-group custom-search-form">
                            <input type="text" class="form-control" placeholder="Search...">
                                <span class="input-group-btn">
                                    <button class="btn btn-default" type="button">
                                        <i class="fa fa-search"></i>
                                    </button>
                                </span>
                        </div>
                        <!-- /input-group -->
                    </li>
                    <li>
                        <a href="/admin"><i class="fa fa-dashboard fa-fw"></i> Dashboard</a>
                    </li>

                    <li>
                        <a href="#"><i class="fa fa-wrench fa-fw"></i>Users<span class="fa arrow"></span></a>
                        <ul class="nav nav-second-level">
                            <li>
                                <a href="/users">All Users</a>
                            </li>

                            <li>
                                <a href="/users/create">Create User</a>
                            </li>

                        </ul>
                        <!-- /.nav-second-level -->
                    </li>

                    <li>
                        <a href="#"><i class="fa fa-wrench fa-fw"></i> Posts<span class="fa arrow"></span></a>
                        <ul class="nav nav-second-level">
                            <li>
                                <a href="/posts">All Posts</a>
                            </li>

                            <li>
                                <a href="/posts/create">Create Post</a>
                            </li>

                        </ul>
                        <!-- /.nav-second-level -->
                    </li>


                    <li>
                        <a href="#"><i class="fa fa-wrench fa-fw"></i>Categories<span class="fa arrow"></span></a>
                        <ul class="nav nav-second-level">
                            <li>
                                <a href="/categories">All Categories</a>
                            </li>

                            <li>
                                <a href="/categories/create">Create Category</a>
                            </li>

                        </ul>
                        <!-- /.nav-second-level -->
                    </li>


                    <li>
                        <a href="#"><i class="fa fa-wrench fa-fw"></i>Media<span class="fa arrow"></span></a>
                        <ul class="nav nav-second-level">
                            <li>
                                <a href="/media">All Media</a>
                            </li>

                            <li>
                                <a href="">Upload Media</a>
                            </li>

                        </ul>
                        <!-- /.nav-second-level -->
                    </li>







                    <li>
                        <a href="#"><i class="fa fa-bar-chart-o fa-fw"></i> Charts<span class="fa arrow"></span></a>
                        <ul class="nav nav-second-level">
                            <li>
                                <a href="flot.html">Flot Charts</a>
                            </li>
                            <li>
                                <a href="morris.html">Morris.js Charts</a>
                            </li>
                        </ul>
                        <!-- /.nav-second-level -->
                    </li>
                    <li>
                        <a href="tables.html"><i class="fa fa-table fa-fw"></i> Tables</a>
                    </li>
                    <li>
                        <a href="forms.html"><i class="fa fa-edit fa-fw"></i> Forms</a>
                    </li>
                    <li>
                        <a href="#"><i class="fa fa-wrench fa-fw"></i> UI Elements<span class="fa arrow"></span></a>
                        <ul class="nav nav-second-level">
                            <li>
                                <a href="panels-wells.html">Panels and Wells</a>
                            </li>
                            <li>
                                <a href="buttons.html">Buttons</a>
                            </li>
                            <li>
                                <a href="notifications.html">Notifications</a>
                            </li>
                            <li>
                                <a href="typography.html">Typography</a>
                            </li>
                            <li>
                                <a href="icons.html"> Icons</a>
                            </li>
                            <li>
                                <a href="grid.html">Grid</a>
                            </li>
                        </ul>
                        <!-- /.nav-second-level -->
                    </li>
                    <li>
                        <a href="#"><i class="fa fa-sitemap fa-fw"></i> Multi-Level Dropdown<span class="fa arrow"></span></a>
                        <ul class="nav nav-second-level">
                            <li>
                                <a href="#">Second Level Item</a>
                            </li>
                            <li>
                                <a href="#">Second Level Item</a>
                            </li>
                            <li>
                                <a href="#">Third Level <span class="fa arrow"></span></a>
                                <ul class="nav nav-third-level">
                                    <li>
                                        <a href="#">Third Level Item</a>
                                    </li>
                                    <li>
                                        <a href="#">Third Level Item</a>
                                    </li>
                                    <li>
                                        <a href="#">Third Level Item</a>
                                    </li>
                                    <li>
                                        <a href="#">Third Level Item</a>
                                    </li>
                                </ul>
                                <!-- /.nav-third-level -->
                            </li>
                        </ul>
                        <!-- /.nav-second-level -->
                    </li>
                    <li class="active">
                        <a href="#"><i class="fa fa-files-o fa-fw"></i> Sample Pages<span class="fa arrow"></span></a>
                        <ul class="nav nav-second-level">
                            <li>
                                <a class="active" href="blank.html">Blank Page</a>
                            </li>
                            <li>
                                <a href="login.html">Login Page</a>
                            </li>
                        </ul>
                        <!-- /.nav-second-level -->
                    </li>
                </ul>


            </div>
            <!-- /.sidebar-collapse -->
        </div>
        <!-- /.navbar-static-side -->
    </nav>





    <div class="navbar-default sidebar" role="navigation">
        <div class="sidebar-nav navbar-collapse">
            <ul class="nav" id="side-menu">
                <li>
                    <a href="/profile"><i class="fa fa-dashboard fa-fw"></i>Profile</a>
                </li>




                <li>
                    <a href="#"><i class="fa fa-wrench fa-fw"></i> Posts<span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level">
                        <li>
                            <a href="">All Posts</a>
                        </li>

                        <li>
                            <a href="">Create Post</a>
                        </li>

                    </ul>
                    <!-- /.nav-second-level -->
                </li>





            </ul>

        </div>

    </div>

</div>






<!-- Page Content -->
<div id="page-wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header"></h1>

                @yield('content')
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
    </div>
    <!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->

</div>
<!-- /#wrapper -->

<!-- jQuery -->
<script src="/js/jquery.js"></script>
<script src="/js/libs.js"></script>
<script src="/js/bootstrap.js"></script>
<script src="/js/scripts.js"></script>
<script src="/js/sb-admin-2.js"></script>
<script src="/js/metisMenu.js"></script>
<!--<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>-->
<!--<script src="https://code.jquery.com/jquery-1.12.4.js" integrity="sha256-Qw82+bXyGq6MydymqBxNPYTaUXXq7c8v3CwiYwLLNXU=" crossorigin="anonymous"></script>-->


@yield('footer')





</body>

</html>

以下是我的create.blade.php

@extends('layouts.admin')




@section('content')


    <h1>Create Users</h1>



@stop

以下是我的 AdminUsersController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

use App\User;

class AdminUsersController extends Controller

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    
        $users = User::all();    

       return view('admin.users.index', compact('users'));
    

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    
        return view('admin.users.create');
    

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    
        //
    

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    
        return view('admin.users.show');
    

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    
        return view('admin.users.edit');

    

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    
        //
    

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    
        //
    

最后是我的路线

Route::resource('admin/users', 'AdminUsersController');`

以下是我file structure的图片

提前谢谢你。

【问题讨论】:

你能分享里面的东西吗index.blade.php index.blade.php 与 create.blade.php 基本相同,只是它不是创建用户,而是在其上写入索引。 分享 index.blade.php 内容 【参考方案1】:

如果create.blade.php 扩展index.blade.php@extends('path_to_index.blade.php') 将解决您的问题。如果create.blade.php 扩展main.blade.phpindex.blade.php 扩展create.blade.php 那么你应该扩展index.blade.php

【讨论】:

以上是关于c9 上的 Laravel Blade 模板仅选择性地扩展到某些页面的主要内容,如果未能解决你的问题,请参考以下文章

使用 Blade 模板的 Laravel 5 表单中预选选项的条件 @if 语句

Laravel 4 Blade 模板文档

laravel-模板引擎Blade

Laravel 中的 Blade 模板与普通 php

laravel模板名字是否必须带blade

Laravel Blade 模板引擎会影响性能吗?