Skip to content

Commit

Permalink
Merge pull request #9 from ajcastro/parameterized-join-method
Browse files Browse the repository at this point in the history
Parameterized join method
  • Loading branch information
ajcastro authored Apr 11, 2020
2 parents cb2693d + b1468bf commit 14158e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ class Post extends Model
],
// This is needed if there is a need to join other tables for derived columns.
'joins' => [
'authors' => ['authors.id', 'posts.author_id']
'authors' => ['authors.id', 'posts.author_id'], // defaults to leftJoin method of eloquent builder
'another_table' => ['another_table.id', 'authors.another_table_id', 'join'], // can pass leftJoin, rightJoin, join of eloquent builder.
]
];

Expand Down
3 changes: 2 additions & 1 deletion src/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public function searchableJoins()
protected function applySearchableJoins($query)
{
foreach ($this->searchableJoins() as $table => $join) {
$query->leftJoin($table, $join[0], '=', $join[1]);
$joinMethod = $join[2] ?? 'leftJoin';
$query->{$joinMethod}($table, $join[0], '=', $join[1]);
}
}

Expand Down

0 comments on commit 14158e3

Please sign in to comment.