Laravel includesToMany不返回相关数据

性感的MF

问题以下我有以下关系。
这是我在数据库中拥有的数据:

ID page_id app_id 96 1 2 97 1 3 98 1 6 99 1 7

这将返回页面,但不会返回相关页面 apps

 $page = App\Page::find(1)->first();
 print_r($page->apps);// this has no results

这是类映射,我在里面有2个组合,在其中您看到“也不起作用”:

class Page extends Model
{
    protected $table = "pages";
    //protected $appends = array('apps');//also not working
    protected $with = array('apps');//


    public function apps(){
        return $this->belongsToMany('App\App','page_apps','page_id','app_id')->withPivot('page_id');

      //return $this->belongsToMany('App\App','page_apps','page_id','app_id');//also not working
    }

    public function getAppsAttribute($value){
        return $value;
    }
}


class App extends Model
{
    protected $table = "apps";
    public $timestamps = true;
}


class PageApps extends Model
{
    protected $table = "page_apps";
    public $timestamps = true;
}
占士再也

删除此功能,它将覆盖->appsfor页面

public function getAppsAttribute($value){
    return $value;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章