找不到类"App \ Post" [英] Class 'App\Post' not found
本文介绍了找不到类"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
这篇关于找不到类"App \ Post"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文