在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/PHP  網(wǎng)絡(luò)安全/ laravel 自定義多態(tài)關(guān)聯(lián)的類型字段 string 轉(zhuǎn) int 的問題?

laravel 自定義多態(tài)關(guān)聯(lián)的類型字段 string 轉(zhuǎn) int 的問題?

自定義多態(tài)關(guān)聯(lián)的類型字段
寫映射

[
1=>'App\Post',
2=>'App\Commit',
]

但是我有多個表是多對多關(guān)系呢?

需要另一套映射

[
1=>'App\Other',
2=>'App\User',
]

多態(tài)關(guān)聯(lián)的表類型都用的int,但是1在不同的model中映射的不同的表,這樣該怎么做呢?

  public function click()
    {
        if ($this->type == 1) {
            return $this->belongsTo('App\Models\HomeList', 'click_id');
        }
        if ($this->type == 2) {
            return $this->belongsTo('App\Models\SlideShow', 'click_id');
        }
        if ($this->type == 3) {
            return $this->belongsTo('App\Models\ReleaseTask', 'click_id');
        }

        return $this->belongsTo('App\Models\HomeList', 'click_id');
    }

上面的代碼結(jié)果 $this->type這個值解析不出來,一個if都沒進(jìn)?。?!
我該怎么辦?

回答
編輯回答
夏木

你是怎么調(diào)用這個click方法的,打印$this->type是沒有值的嗎?

2017年12月31日 08:37