Created
March 28, 2021 15:11
-
-
Save vidux/87c734b0f6fabbb5a838a8d25074c1d7 to your computer and use it in GitHub Desktop.
Laravel BelongsToOneThrough like relationship
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Model story | |
/* | |
`Spreedsheet` have many `Rows` `Row` have many `RowValues` | |
`Spreedsheet` parent of `Rows`, `Rows` parent of `RowValues` | |
*/ | |
//table structure | |
/* | |
`Spreedsheet` | |
------------ | |
|id | name | | |
----------- | |
`Rows` | |
---------------------- | |
|id | spreedsheet_id | | |
--------------------- | |
`RowValues` | |
---------------------- | |
|id | row_id | value | | |
---------------------- | |
*/ | |
//get `Spreedsheet` from RowValues Table | |
class RowValues extends Model | |
{ | |
public function spreedsheet() | |
{ | |
return $this->hasOneThrough(Spreedsheet::class,Rows::class,'id','id', 'row_id' ,'spreedsheet_id') ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment