Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/akiyamasm/lazybelongstomany
- Owner: akiyamaSM
- Created: 2021-09-23T14:07:58.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-01T17:17:02.000Z (about 3 years ago)
- Last Synced: 2024-06-19T23:12:07.061Z (5 months ago)
- Topics: eloquent, laravel, php
- Language: PHP
- Homepage:
- Size: 14.6 KB
- Stars: 24
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.