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大虾 帮忙 指点下
{
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大虾 帮忙 指点下
1 个回复
[已注销]
赞同来自: 邂逅的流年
要把第一个参数类名写全了, 默认命名空间是App
上边是5.0的写法
5.1以后可以