Last active
October 14, 2019 08:33
-
-
Save einnar82/90d35d3b66b26c226c0fcfc951d02e4f to your computer and use it in GitHub Desktop.
Indexing Eloquent
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 | |
namespace App\Rise\Traits; | |
trait CanIndexQueries | |
{ | |
/** | |
* Example | |
* $properties = Property::indexRaw('USE INDEX (brand)') | |
* ->with('brand', 'information')->where('status', 'active') | |
* ->where('status', 'active') | |
* ->where('brand', $brandCode) | |
* ->orderBy('property_name') | |
* ->get(); | |
*/ | |
public static function indexRaw($index_raw) | |
{ | |
$model = new static(); | |
$model->setTable(\DB::raw($model->getTable() . ' ' . $index_raw)); | |
return $model; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment