Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thiagoprz/eloquent-composite-key
Eloquent Composite Key Support Package
https://github.com/thiagoprz/eloquent-composite-key
Last synced: 3 months ago
JSON representation
Eloquent Composite Key Support Package
- Host: GitHub
- URL: https://github.com/thiagoprz/eloquent-composite-key
- Owner: thiagoprz
- License: mit
- Created: 2021-02-24T13:33:04.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-10-24T00:26:25.000Z (about 1 year ago)
- Last Synced: 2024-09-08T06:29:40.443Z (3 months ago)
- Language: PHP
- Size: 36.1 KB
- Stars: 47
- Watchers: 3
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: License.txt
Awesome Lists containing this project
- awesome-laravel-filament - Laravel Eloquent Composite Key
README
# Eloquent Composite Key
Package to enable composite key support on Eloquent Models.## Installation
Install it with composer:`composer require thiagoprz/eloquent-composite-key`
## Usage
Define the primaryKey as an array and use the HasCompositeKey trait on your model class.
```
$key1,
'key_2' => $key2,
]);
...
// Throws ModelNotFoundException
$user = User::findOrFail([
'key_1' => $key1,
'key_2' => $key2,
]);
...
```The main idea of this package is to allow Laravel projects use composite keys on models despite Eloquent not supporting them officially (see https://laravel.com/docs/8.x/eloquent#composite-primary-keys).
## License
[MIT](https://github.com/thiagoprz/eloquent-composite-key/blob/master/License.txt)