Skip to content

Instantly share code, notes, and snippets.

@moiroca
Forked from goranprijic/BaseModel.php
Last active May 18, 2016 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moiroca/3e4c4029351b625e43fc677851a7d798 to your computer and use it in GitHub Desktop.
Save moiroca/3e4c4029351b625e43fc677851a7d798 to your computer and use it in GitHub Desktop.
Check if table is already joined in Laravel Query Builder
<?php
class BaseModel extends Eloquent {
public static function isJoined($query, $table)
{
$joins = $query->getQuery()->joins;
if($joins == null) {
return false;
}
return in_array($table, array_map( function($join) { return $join->table; }, $joins));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment