Laravel一对一关系会从数据库返回所有相关资源吗?

I'm currently on an instance where a User has one Pension as the case in Laravel One-To-One relationship. With the code sample below I still wonder why it returns all associated records from the database instead of one.

用户模型

public function pension(){
    return $this->hasOne(Pension::class)->latest();
}

养老金模式

public function user(){
    return $this->belongsTo(User::class);
}

Then in my Pension Controller, with App\User imported,

public function user($id){

        $user = User::find($id);
        return PensionResource::collection(  
            $user->pension()->with(
                $this->particulars()
            )->get() 
        );
    }

private function particulars(){
        return [
            'user:id,surname,first_name,other_name',
            'pension_manager:id,name'
        ];
    }

请注意,我有意允许用户在数据库中有多个记录。有什么可能的解决方法?

评论