Laravel 4 获得雄辩(Laravel)返回没有关系的对象 请考虑用户模型中的这种方法: use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableInterface; use Cartalyst\Sentry\Users\Eloquent\User as SentryUserModel; class User extends SentryUserModel implements UserInterface, RemindableInterface { //[...] public function company() { Log::info("SPOOFED", array($this->getSpoofedCompanyId())); // == 1 if($this->getSpoofedCompanyId() > 0) { return Company::find($this->getSpoofedCompanyId()); } else { return $this->belongsTo('Company'); } }

Laravel 4 获得雄辩(Laravel)返回没有关系的对象 请考虑用户模型中的这种方法: use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableInterface; use Cartalyst\Sentry\Users\Eloquent\User as SentryUserModel; class User extends SentryUserModel implements UserInterface, RemindableInterface { //[...] public function company() { Log::info("SPOOFED", array($this->getSpoofedCompanyId())); // == 1 if($this->getSpoofedCompanyId() > 0) { return Company::find($this->getSpoofedCompanyId()); } else { return $this->belongsTo('Company'); } },laravel-4,eloquent,Laravel 4,Eloquent,这会产生以下错误: LogicException Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation 我猜我不允许返回一个没有关系的对象?有没有办法绕过这个 原因是我让一个超级用户冒充另一个用户。你能尝试替换return$this->belongsTo'Company';使用类似退货公司::查找$this->Company_id?!

这会产生以下错误:

LogicException
Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation
我猜我不允许返回一个没有关系的对象?有没有办法绕过这个

原因是我让一个超级用户冒充另一个用户。

你能尝试替换return$this->belongsTo'Company';使用类似退货公司::查找$this->Company_id?!