首页 文章

laravel:关系方法必须返回一个类型为Illuminate \ Database \ Eloquent \ Relations \ Relation的对象

提问于
浏览
23

我有3个DB表,我没有任何关系 . 然后我写了下面的代码:

public function store($key)
{
    $user_key = md5(Input::get('email') . "-" . strtotime('now'));

    $user = new User;

    $user->name = Input::get('name');
    $user->email = Input::get('email');
    $user->user_key = $user_key;
    $user->password = Hash::make(Input::get('password'));
    $user->apipass = md5(Input::get('password'));
    $user->save();

    $newUid = $user->id;

    //check key for share
    $invited = DB::table('invites')->where('invite_key', Input::get('invite_key'))->where('status', '0')->count();

    if($invited == 1) {
        $inviter_id = DB::table('invites')->where('invite_key', Input::get('invite_key'))->where('status', '0')->pluck('user_id');
        $read_only = DB::table('invites')->where('invite_key', Input::get('invite_key'))->where('status', '0')->pluck('read_only');

        $share = new RecordShare;

        $share->user_id = $inviter_id;
        $share->shared_with_id = $newUid;
        $share->read_only = $read_only;
        $share->save;

    }

    return Redirect::to('login');
}

它应该创建一个新用户,然后看看谁邀请了他,然后用邀请者创建一个共享记录 .

但是当我测试它时,我得到了错误:

LogicException关系方法必须返回类型为Illuminate \ Database \ Eloquent \ Relations \ Relation的对象

打开:/home/oneinfin/public_html/dialysis/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php

*/
protected function getRelationshipFromMethod($key, $camelKey)
{
$relations = $this->$camelKey();
if ( ! $relations instanceof Relation)
{
throw new LogicException('Relationship method must return an object of type '
. 'Illuminate\Database\Eloquent\Relations\Relation');
}

我以为我的数据有问题,所以试图创建一个空记录

$share = new RecordShare;
        $share->save;

但这也失败了同样的错误 . 如果我完全删除这部分,该功能才会通过 .

什么可能是错的?我试图清除缓存,但仍然无法正常工作 .

1 回答

  • 87

    我想改变

    $share->save;
    

    $share->save();
    

相关问题