Skip to content

Instantly share code, notes, and snippets.

@einnar82
Last active October 14, 2019 08:33
Show Gist options
  • Save einnar82/90d35d3b66b26c226c0fcfc951d02e4f to your computer and use it in GitHub Desktop.
Save einnar82/90d35d3b66b26c226c0fcfc951d02e4f to your computer and use it in GitHub Desktop.
Indexing Eloquent
<?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