【问题标题】:index view isn't showing索引视图未显示
【发布时间】:2019-12-19 18:23:08
【问题描述】:

您好,我创建了一个新的默认索引视图,但它没有加载其内容并显示空白页,我的文件结构https://ibb.co/wW337xS

索引刀片:

  @extends('layouts.frontLayout.front_design')

  @section('content')

    <!--html here-->

  @endsection

控制器:

  <?php

  namespace App\Http\Controllers;

  use App\Index;
  use Illuminate\Http\Request;

  class IndexController extends Controller
  {
      public function index()
      {
          return view('index');
      }

路线:

Route::resource('/','IndexController');

【问题讨论】:

  • 您的视图没有内容?只是对它的评论?检查源头,那里有什么?
  • “layouts.frontLayout.front_design”是否存在?您的文件名为 index.blade.php,位于 ressources/views/ ?
  • @Qirel 检查显示所有内容
  • @jtwes 是的,它存在于其中我刚刚写了 @include('layouts.frontLayout.front_header') @yield('content') @include('layouts.frontLayout.front_footer')
  • 好吧,那么它实际上并没有显示任何东西——所以在那里添加一些 HTML 吗?将&lt;!--html here--&gt; 替换为一些实际 文本,例如&lt;p&gt;Hello world&lt;/p&gt;?

标签: laravel eloquent laravel-5.8


【解决方案1】:

错误

Route::resource('/','IndexController');

Route::get('/', 'IndexController@index');

【讨论】:

  • 完全不正确。它们都是有效的,但资源添加了一堆有用的路线。
【解决方案2】:

发生了它的问题,因为您将用户发送到名称为“index”的视图,这意味着您的resourceview 文件夹中有一个刀片页面,但正如我在您的结构中看到的那样, index.blade.php 在这个地址:layouts.index。然后你可以重构你的控制器:

public function index()
      {
          return view('layouts.index');
      }

【讨论】:

  • 查看 [layouts.index] 未找到。
  • 如果您的索引位于视图的根目录中,那么您的代码没有任何问题,而且看起来还可以。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-24
  • 1970-01-01
  • 2018-11-16
  • 1970-01-01
  • 2013-06-26
  • 2012-01-31
相关资源
最近更新 更多