jestillore/has-one-belongs-to

使用 Pivot 的 Laravel Eloquent 一对一关系

v6.0.3 2024-02-28 07:50 UTC

This package is auto-updated.

Last update: 2024-08-28 09:17:43 UTC


README

与 Laravel Eloquent 的 Pivot 一对一关系。

这与 Eloquent 的 belongsToMany 相同。唯一的区别是模型只会与单个模型相关联,而不是与模型集合相关联。

安装

composer require jestillore/has-one-belongs-to

使用示例

数据库表

courses

users

student_data

代码使用
class Course
{
    
}

class User
{
    use HasOneBelongsToRelationship;
    
    public function course()
    {
        return $this->hasOneBelongsTo(Course::class, 'student_data');
    }
}

版本控制

我决定放弃与 illuminate 版本同步的一切,以避免每次 Laravel 升级到新版本时都需要升级。

作者

Jillberth Estillore – @ejillberthejillberth@gmail.com

在 MIT 许可证下分发。有关更多信息,请参阅 LICENSE

https://github.com/jestillore/has-one-belongs-to