'Class 'App\Post' not found [duplicate]

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

enter image description here

My code structure is in snapshot Thanks



Solution 1:[1]

Add the namespace in the beginning of file like and use Model rather than eloquent class to extend

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;

class Post extends Model {

}

It will work for laravel >5.0 .

Solution 2:[2]

You should add below statements at top of your Post.php file, like this...

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

Now, in BlogController.php add the below statement at top of the file, like...

<?php

use App\Post;

will work definitely in Laravel 5>=

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Ketan Trentiya