在laravel-5.8中找不到类'App \ Http \ Controllers \ Post'

时间:2019-07-14 08:08:25

标签: laravel eloquent laravel-5.8

他试图在索引页上显示数据,但它说:未找到类'App \ Http \ Controllers \ Post'

控制器:

  <?php

  namespace App\Http\Controllers;

  use Illuminate\Http\Request;

  class IndexController extends Controller
  {

      public function index()
      {
          $data = Post::all();
          return view('index', compact('data'));
       }

1 个答案:

答案 0 :(得分:2)

您需要添加以下行:

use App\Post;

现在您的代码应如下所示:

<?php

  namespace App\Http\Controllers;

  use Illuminate\Http\Request;
  use App\Post;

  class IndexController extends Controller
  {

          public function index()
          {
              $data = Post::all();
              return view('index', compact('data'));
           }