获得Eloquent(Laravel)无关系地返回对象

时间:2014-01-13 07:56:17

标签: laravel-4 eloquent

请在用户模型中考虑此方法:

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');
    }
}

这会产生以下错误:

LogicException
Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation

我想我不允许归还一个没有关系的物体?有没有办法绕过这个?

原因是我让超级用户冒充其他用户。

0 个答案:

没有答案