layout.blade.php 中的$slot 显示未定义变量错误

问题描述 投票:0回答:1

我有

layout.blade.php
,位于resources/view/components/admin/layout/layout.blade.php。 我有
home.blade.php
,位于 resources/view/components/admin/home/home.blade.php。

我试图用

home.blade.php
包裹
layout.blade.php
,但它一直给我
Undefined variable $slot
,但是当我尝试以相反的方式包裹时(意思是当我用
layout
包裹
home
时,它正在工作。我会的)在下面提供我的代码。

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">
     <title>Majestic Admin</title>
     <link rel="stylesheet" href="admin/vendors/mdi/css/materialdesignicons.min.css">
     <link rel="stylesheet" href="admin/vendors/base/vendor.bundle.base.css">
     <link rel="stylesheet" href="admin/vendors/datatables.net-bs4/dataTables.bootstrap4.css">
     <link rel="stylesheet" href="admin/css/style.css">
     <link rel="shortcut icon" href="admin/images/favicon.png" />

     <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">

      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8sh+WyWp9o7BuoBMVA+PQ9SsB+q7UHEI9I0JjD" crossorigin="anonymous">

      <link rel="stylesheet" href="css/bootstrap-multiselect.css" type="text/css"/>
     </head>


    <body>
     <div class="container-scroller">

     <x-admin.navbar />

     <div class="container-fluid page-body-wrapper">

     <x-admin.sidebar />

     <div class="main-panel">
        {{$slot}}
      <x-admin.footer />
      </div>
     </div>
    </div>

    <script src="admin/vendors/base/vendor.bundle.base.js"></script>
  
    <script src="admin/vendors/chart.js/Chart.min.js"></script>
    <script src="admin/vendors/datatables.net/jquery.dataTables.js"></script>
    <script src="admin/vendors/datatables.net-bs4/dataTables.bootstrap4.js"></script>

    <script src="admin/js/off-canvas.js"></script>
    <script src="admin/js/hoverable-collapse.js"></script>
    <script src="admin/js/template.js"></script>

    <script src="admin/js/dashboard.js"></script>
    <script src="admin/js/data-table.js"></script>
    <script src="admin/js/jquery.dataTables.js"></script>
    <script src="admin/js/dataTables.bootstrap4.js"></script>

    <script src="admin/js/jquery.cookie.js" type="text/javascript"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>


     <script type="text/javascript" src="js/jquery.min.js"></script>
     <script type="text/javascript" src="js/bootstrap.min.js"></script>
     <script type="text/javascript" src="js/bootstrap-multiselect.js"></script>
     <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

    </body>

    </html>

home.blade.php

      @props(['blog', 'category', 'tag', 'comment'])

      <div class="content-wrapper">
       <div class="row">

      {{-- Top --}}
      <div class="col-md-12 grid-margin stretch-card">
        <div class="card">
          <div class="card-body dashboard-tabs p-0">
            <div class="tab-content py-0 px-0">
              <div class="tab-pane fade show active" id="overview" role="tabpanel" aria-labelledby="overview-tab">
                <div class="d-flex flex-wrap justify-content-xl-between">
                  <div class="d-none d-xl-flex border-md-right flex-grow-1 align-items-center justify-content-center p-3 item">
                    <i class="mdi mdi-calendar-heart icon-lg me-3 text-primary"></i>
                    <div class="d-flex flex-column justify-content-around">
                      <small class="mb-2 text-muted">Total Blogs</small>
                      <h5 class="me-2 mb-0">{{$blog->count()}}</h5>
                    </div>
                  </div>
                  <div class="d-flex border-md-right flex-grow-1 align-items-center justify-content-center p-3 item">
                    <i class="mdi mdi-clipboard-text
                    \f244 me-3 icon-lg text-danger"></i>
                    <div class="d-flex flex-column justify-content-around">
                      <small class="mb-2 text-muted">Total Categories</small>
                      <h5 class="me-2 mb-0">{{$category->count()}}</h5>
                    </div>
                  </div>
                  <div class="d-flex border-md-right flex-grow-1 align-items-center justify-content-center p-3 item">
                    <i class="mdi mdi-tag-multiple
                    \f5e9 me-3 icon-lg text-danger"></i>
                    <div class="d-flex flex-column justify-content-around">
                      <small class="mb-2 text-muted">Total Tags</small>
                      <h5 class="me-2 mb-0">{{$tag->count()}}</h5>
                    </div>
                  </div>
                  <div class="d-flex border-md-right flex-grow-1 align-items-center justify-content-center p-3 item">
                    <i class="mdi mdi-eye me-3 icon-lg text-success"></i>
                    <div class="d-flex flex-column justify-content-around">
                      <small class="mb-2 text-muted">Unique Blog Viewed</small>
                      <h5 class="me-2 mb-0">200</h5>
                    </div>
                  </div>
                  <div class="d-flex border-md-right flex-grow-1 align-items-center justify-content-center p-3 item">
                    <i class="mdi mdi-comment
                    \f270 me-3 icon-lg text-warning"></i>
                    <div class="d-flex flex-column justify-content-around">
                      <small class="mb-2 text-muted">Total Blog Comments</small>
                      <h5 class="me-2 mb-0">{{$comment->count()}}</h5>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      {{-- left side --}}
      <div class="col-md-6 grid-margin stretch-card">
        <div class="card">
          <div class="card-body">
            <p class="mb-4 card-title">Recent Posts</p>

            <div class="row p-2 mb-4" >
                @foreach ($blog->take(4) as $blog)
                  <a href="/blogs/{{$blog->slug}}" style="text-decoration: none; color: inherit">
                    <div class="row p-2 mb-4">
                      <div class="col-md-4">
                        <img src="/blog/assets/images/about-us.jpg" class="img-fluid" alt="Your Alt Text">
                      </div>
                      <div class="col-md-8">
                        <p class="card-description mb-2">{{$blog->category->name}}</p>
                        <h4 class="card-title text-primary mb-2">{{$blog->title}}</h4>
                        <p class="mb-">{{$blog->intro}}</p>
                      </div>
                    </div>
                  </a>
                @endforeach
                
            </div>

            

          </div>
        </div>
      </div>

      {{-- right side --}}
      <div class="col-md-6 grid-margin stretch-card">
        <div class="card">
          <div class="card-body">
            <p class="mb-4 card-title">Recent Comments</p>

            @foreach ($comment->take(5) as $comment)
              <a href="/blogs/{{$comment->blog->slug}}" style="text-decoration: none; color: inherit">
                <div class=" p-4 pb-2 mb-4 pt- border rounded cursor-pointer">
                  <div class="col-md-12">
                      <h4 class="card-title text-primary mb-2">{{$comment->blog->title}}</h4>
                      <p class="card-description mb-2">{{$comment->name}}</p>
                      <p class="mb-2">{{$comment->body}}</p>
                  </div>
                </div>
              </a>
            @endforeach

            

          </div>
        </div>
      </div>

    </div>
  </div>

请帮我解决这个问题。

laravel components
1个回答
0
投票

已解决:在我的控制器中,我正在调用layout.blade.php,而我应该调用home.blade.php。菜鸟错误。谢谢大家。

© www.soinside.com 2019 - 2024. All rights reserved.