shomisha / unusual-relationships
This package offers a trait which provides your models with the ability to have relationships not included within standard Laravel installations.
Installs: 1 038
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 1
Forks: 2
Open Issues: 1
Requires
- php: ~7.0
- laravel/framework: >=5.6
Requires (Dev)
- orchestra/testbench: ~3.8
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-11-16 23:03:39 UTC
README
This package is meant to provide its users with an API to accessing relationships that aren't included in Laravel's base installation. It achieves this effect by utilizing a trait which in turn instantiates custom relationship classes which rely on Laravel's relationship scaffolding.
class Employee extends Model { public function tasks() { return $this->belongsToMany(Task::class); } public function boss() { return $this->belongsTo(Boss::class); } } class Boss extends Model { use Shomisha\UnusualRelationships\HasUnusualRelationships; public function employees() { return $this->hasMany(Employee::class); } public function tasks() { return $this->belongsToManyThrough(Task::class, Employee::class) } }
The example above shows how you can use the belongsToManyThrough
relationship to connect your model to its distantly related models.
To learn more about this which methods work with which database structures, as well as how to use those methods, head over to our wiki pages.