Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/akiyamasm/lazybelongstomany

A lightweight implementation of Laravel's belongs To many
https://github.com/akiyamasm/lazybelongstomany

eloquent laravel php

Last synced: 1 day ago
JSON representation

A lightweight implementation of Laravel's belongs To many

Awesome Lists containing this project

README

        

# LazyBelongsToMany
A lightweight implementation of Laravel's belongs To many relationship in cases you don't need pivot table.

## Installation

First, install the package through Composer.
```php
composer require inani/lazy-belongs-to-many
```

### Usage

Suppose we have the following database structure. A ``User`` can be linked to one or many ``Tag``. instead of creating the pivot table we can save tags id list in a column on the user table.
````
| id | name | tags_id |
|----|-------------------|---------------|
| 1 | El Houssain inani | [1, 10, 4, 33]|
````

````php

'array' // <=== IMPORTANT
];


/**
* Tags
* @return mixed
*/
public function tags()
{
return $this->belongsToManyInArray(Tag::class);
}
}
````

For the time being there is no implementation for the inverse. I'll be happy to see your contribution at any way.

Happy Coding.