tishotm / eloquent-ci-relations
Eloquent case-insensitive relations
Installs: 23 245
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 5
Open Issues: 0
Requires
- illuminate/database: ^5.5.33 || ^6.20.26 || ^7.30.4 || ^8.40.0 || ^9.0 || ^10.0 || ^11.0
Requires (Dev)
- php: ~7.1 || ~8.0
- mockery/mockery: ~1.0
- phpunit/phpunit: ~6.0 || ~7.0 || ~8.0
This package is auto-updated.
Last update: 2024-11-06 17:07:46 UTC
README
Using Eloquent out of the box on case-insensitive collation databases could potentially return incomplete collection of items if the foreign keys are set as strings and they differ in terms of uppercase vs lowercase. On eager loaded relations Eloquent builds a dictionary of the parent models and associates their related models by their keys. PHP is case-sensitive and therefore if the keys are different, then some of the related models will not be returned. This package simply normalizes the dictionary keys into lowercase.
Example:
Items table
Tags table
item_tag table
Item::with('tags')->find('aaa');
The related tags would include only the "tag 2" even if the the DB collation is case-insensitive and the returned query data includes "tag 1".
With case insensitive relations: The related tags would include both "tag 1" and "tag 2".
Requirements
- illuminate/database 5.5.33 and up, 5.6.*, 5.7.*, 5.8.*, 6.20.26 and up, 7.30.4, 8.40.0 an up
Installation
composer require tishotm/eloquent-ci-relations
Usage
use Illuminate\Database\Eloquent\Model; class Item extends Model { use \TishoTM\Eloquent\Concerns\HasCiRelationships; // ... relations }