model hasOne() 一对一 控制器调用

class Post extends Model
{
protected $table = 'posts';
public function hasManyPages(){
return $this->hasOne('pages','post_id','id');
}
}

class PostController extends Controller
{
public function index()
{
$posts = Post::find(1)->hasManyPosts;
print_r($posts);
}
}

Whoops, looks like something went wrong.
1/1 FatalErrorException in Model.php line 770:
Class 'pages' not found

我这里 换成 App\pages 也是一样的报这个错误

求各位i大虾 帮忙 指点下
已邀请:
$this->hasOne('pages','post_id','id');

要把第一个参数类名写全了, 默认命名空间是App
$this->hasOne('\App\pages','post_id','id');

上边是5.0的写法

5.1以后可以
use App\pages;
...
$this->hasOne(pages::class,'post_id','id');

要回复问题请先登录注册