MySQL表: 帖子 標籤 post_tag(與列POST_ID和TAG_ID)許多一對多(belongsToMany)Laravel關係似乎並不HHVM下工作
// Post.php model
class Post extends Eloquent {
protected $table = 'posts';
public $timestamps = true;
protected $guarded = ['id'];
public function tags()
{
return $this->belongsToMany('Tag');
}
}
// Tag.php model
class Tag extends Eloquent {
protected $table = 'tags';
public $timestamps = false;
protected $guarded = ['id'];
public function posts()
{
return $this->belongsToMany('Post');
}
}
// on routes.php
Route::get('/', function()
{
$post = Post::find(44);
echo $post . '<br>';
$tag = Tag::find(28);
echo $tag;
return $post->tags;
});
擊球時
/它打印後:44,它打印標籤:28和給出
ErrorException不能使用的標量值作爲數組
訪問Post.php標記()函數上的標記屬性時。 請記住,在post_tag的表格中有一個post_id = 44和tag_id = 28的條目,但它可能爲空。 Laravel/php在嘗試訪問belongsToMany('Tag')方法時給了我這個錯誤。
我究竟做錯了什麼?
我一直在進一步研究的問題納入框架的代碼發現,如果我而不是右像這樣的關係,它的工作原理: 公共功能標籤() \t { \t \t回$這個 - > belongsToMany( '標籤',NULL,NULL,NULL,「什麼功能於這裏而不是空「); \t} – mwm
嘿,HHVM準備好了嗎? –