megapixel23/belongs-to-one
最新稳定版本:2.0.0
Composer 安装命令:
composer require megapixel23/belongs-to-one
包简介
Belongs To One Laravel 5 Relation class
README 文档
README
Based on Belongs To Many Relation. Returns one model instead of Collection of models.
Installation
composer require megapixel23/belongs-to-one
Usage
BelongsToOne relation is almost identical to standard BelongsToMany except it returns one model instead of Collection of models and null if there is no related model in DB (BelongsToMany returns empty Collection in this case). Include Megapixel23\Database\Eloquent\Relations\BelongsToOneTrait within your Model and use BelongsToOne relation.
Example:
<?php namespace App\Models; use App\Models\Group; Use Illuminate\Database\Eloquent\Model; use Megapixel23\Database\Eloquent\Relations\BelongsToOneTrait; class Record extends Model { use BelongsToOneTrait; public function group() { return $this->belongsToOne(Group::class); } }
And then use it like any other relation:
$record = Record::with('group')->first();
Testing
./vendor/bin/phpunit
统计信息
- 总下载量: 1.62k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-27