找不到类"App \ Post"

问题描述:

我正在研究 laravel 5.2使用Jquery进行AJAX分页我已将post类定义为

I am working on laravel 5.2 AJAX Pagination with Jquery I have defined my post class as

Post.php

<?php

class Post extends Eloquent
{
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'posts';

    /**
     * Define guarded columns
     *
     * @var array
     */
    protected $guarded = array('id');
}

BlogController.php

<?php

class BlogController extends Controller
{
  /**
     * Posts
     *
     * @return void
     */
    public function showPosts()
    {
      $posts = Post::paginate(5);

        if (Request::ajax()) {
            return Response::json(View::make('posts', array('posts' => $posts))->render());
        }

        return View::make('blog', array('posts' => $posts));
    }
}

请帮助我将此课程粘贴到正确的位置.我知道模型类丢失的错误,但不知道如何摆脱

Kindly help me where to paste this class to go right . I know its error that model class is missing but dont know how to get rid of

我的代码结构在快照中谢谢

My code structure is in snapshot Thanks

您的 Post.php 模型应为

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    //
}

BlogController.php 文件中,在顶部添加以下行

In BlogController.php file add below lines on top

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

use App\Post;

阅读:- https://laravel.com/docs/5.2/eloquent