-
-
Save laudaikinhdi/c7e7447213aceccdb2eb953831aa3194 to your computer and use it in GitHub Desktop.
Revisions
-
InToSSH revised this gist
Apr 20, 2021 . No changes.There are no files selected for viewing
-
InToSSH created this gist
Apr 19, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ <?php Builder::macro('orderByRelation', function(string $searchColumn, string $dir) { list($relation, $column) = explode('.', $searchColumn); $relation_table = $this->getRelation($relation)->getModel()->getTable(); $relation_foreign_key = $this->getRelation($relation)->getForeignKeyName(); $query_table = $this->getModel()->getTable(); $this->select($query_table . '.*') ->join($relation_table, $query_table . '.' . $relation_foreign_key, '=', $relation_table . '.id') ->orderBy($relation_table . '.' . $column, $dir); });