Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/payter/has-column-many
Coma separated IDs, JSON and PHP Serialized relationships for Laravel Eloquent models
https://github.com/payter/has-column-many
eloquent eloquent-database eloquent-models eloquent-orm eloquent-relations eloquent-relationships laravel php
Last synced: 2 months ago
JSON representation
Coma separated IDs, JSON and PHP Serialized relationships for Laravel Eloquent models
- Host: GitHub
- URL: https://github.com/payter/has-column-many
- Owner: PayteR
- License: mit
- Created: 2022-04-09T13:20:32.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-20T10:10:12.000Z (over 2 years ago)
- Last Synced: 2024-09-18T04:17:59.925Z (4 months ago)
- Topics: eloquent, eloquent-database, eloquent-models, eloquent-orm, eloquent-relations, eloquent-relationships, laravel, php
- Language: PHP
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Comma separated IDs, JSON and PHP Serialized relationships for Laravel Eloquent models
You will be able to make relations of comma separated values in your MySQL table super easely, with adding just few lines of code into your Eloquent model.
It
So if you use Laravel and your relations in the table looks like this, then this package is for you:
![Comma separated example](./docs/table-example.png)
![PHP Serialized example](./docs/table-serialized-example.png)## Installation
Require package with composer
```PHP
composer require payter/has-column-many
```## Basic usage
Using of this package is super easy - you just need to include `UseColumnMany` trait to your model.
```PHP
hasColumnMany(RelatedModel::class, 'related_ids');
}
}
```And you can call it like any other [Eloquent relationships](https://laravel.com/docs/9.x/eloquent-relationships)
```PHP
use App\Models\ModelName;
$relateds = ModelName::find(1)->relateds;
foreach ($relateds as $related) {
//
}
```## Advanced usage
### Multiple columns
You are able to concat ID's even from more than one column! It's easy - just pass an array of column names as second parameter:
```PHP
return $this->hasColumnMany(RelatedModel::class, ['related_ids', 'another_column_ids']);
```### JSON and Serialised ID's
You don't need to do anything, it will automatically asume if it's comma separated or JSON or Serialized.
## You can