PHPackages                             megapixel23/belongs-to-one - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. megapixel23/belongs-to-one

ActiveLibrary[Database &amp; ORM](/categories/database)

megapixel23/belongs-to-one
==========================

Belongs To One Laravel 5 Relation class

2.0.0(8y ago)71.7k2[1 issues](https://github.com/MEGApixel23/belongs-to-one/issues)MITPHP

Since May 12Pushed 8y ago2 watchersCompare

[ Source](https://github.com/MEGApixel23/belongs-to-one)[ Packagist](https://packagist.org/packages/megapixel23/belongs-to-one)[ RSS](/packages/megapixel23-belongs-to-one/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (4)Used By (0)

Belongs To One Relation for Laravel 5.5
=======================================

[](#belongs-to-one-relation-for-laravel-55)

[![Travis CI](https://camo.githubusercontent.com/6498955a78d88883591ba73125312ba47e70061fa8817ea33dd4a4e3ffeaf3a2/68747470733a2f2f7472617669732d63692e6f72672f4d454741706978656c32332f62656c6f6e67732d746f2d6f6e652e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/6498955a78d88883591ba73125312ba47e70061fa8817ea33dd4a4e3ffeaf3a2/68747470733a2f2f7472617669732d63692e6f72672f4d454741706978656c32332f62656c6f6e67732d746f2d6f6e652e7376673f6272616e63683d6d6173746572)

Based on [Belongs To Many](https://laravel.com/docs/5.3/eloquent-relationships#defining-relationships) Relation. Returns one model instead of Collection of models.

### Installation

[](#installation)

` composer require megapixel23/belongs-to-one`

### Usage

[](#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:

```
