jeidison / composite-key
Laravel composite key
Installs: 5 308
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^7.0|^8.0
Requires (Dev)
README
==========
The problem
Eloquent doesn't support composite keys.
Installation
$ composer require jeidison/composite-key
Usage
Add Trait of your model
namespace App; use Illuminate\Database\Eloquent\Model; class MyClass extends Model { use Jeidison\CompositeKey\CompositeKey; ... }
- Find
public function index() { $modelX = ModelX::find(1); // or $modelX = ModelX::find(['c1' => 1, 'c2' => 2]); }
- FindOrFail
public function index() { $modelX = ModelX::findOrFail(1); // or $modelX = ModelX::findOrFail(['c1' => 1, 'c2' => 2]); }
- FindMany
public function index() { $modelX = ModelX::findMany([['c1' => 1, 'c2' => 2]]); // or $modelX = ModelX::findMany([['c1' => 1, 'c2' => 2], ['a1' => 1, 'a2' => 2]]); }
- Model Fresh
public function index() { $modelX = ModelX::find(1); $freshModelX = $modelX->fresh(); }
- Model Refresh
public function index() { $anyWhatever = Anything::find(1); $freshAnyWhatever = $anyWhatever->refresh(); }
- Model Delete
public function index() { $modelX = ModelX::find(1); $modelX->delete(); }
- Model Destroy
public function index() { $count = ModelX::destroy(['c1' => 1, 'c2' => 2]); // or $count = ModelX::destroy([['c1' => 1, 'c2' => 2], ['a1' => 1, 'a2' => 2]]); }
- FirstOrCreate
$modelX = ModelX::firstOrCreate(['name' => 'Test 10']); $modelX = ModelX::firstOrCreate( ['name' => 'Test 10'], ['delayed' => 1, 'arrival_time' => '11:30'] );
- FirstOrNew
$modelX = ModelX::firstOrNew(['name' => 'Test 10']); $modelX = ModelX::firstOrNew( ['name' => 'Test 10'], ['delayed' => 1, 'arrival_time' => '11:30'] );
- IncrementOrDecrement
// Not implemented
- Eloquent\Collection::find
// Not implemented
- Eloquent\Collection::fresh
// Not implemented
- Authenticatable::getAuthIdentifierName
// Not implemented
- Authenticatable::getAuthIdentifier
// Not implemented
- Model::getRouteKey
// Not implemented
- Model::getRouteKeyName
// Not implemented
- SerializesAndRestoresModelIdentifiers
// Not implemented
Authors
License
composite-key is licensed under the MIT License.