Laravel 5.2属于与条件不起作用的关系

Ric*_*NDY 0 php laravel laravel-5.2

belongsTo()关系如下问题.

我的模特

class TypeOne extends Model{

}
===============================
class TypeTwo extends Model{

}
===============================
class Post extends Model{
    public function typeOne(){
        return $this->belongsTo('Type','type_id')->where('object_type','type_one');
    }
    public function typeTwo(){
        return $this->belongsTo('Type','type_id')->where('object_type','type_two');
    }

    public function getPost(){
        return Post::with(['typeOne','typeTwo'])->get();
    }
}
Run Code Online (Sandbox Code Playgroud)

我会得到错误 column "object_type" does not exist

我该怎么办?

Ram*_*rai 6

在关系函数中,请正确建模.

可能这也是一个错误.如果你已经输入模型..你有模型..?

您需要在这种情况下使用多态概念.

多态laravel 5.2