Ramzan Mahmood Ramzan Mahmood - 2 months ago 5
jQuery Question

Class 'App\Post' not found

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

Answer

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>=