Skip to content

Instantly share code, notes, and snippets.

@kevsersrca
Created August 2, 2017 08:31
Show Gist options
  • Save kevsersrca/fa67a0afa818911925ece9d00519f3aa to your computer and use it in GitHub Desktop.
Save kevsersrca/fa67a0afa818911925ece9d00519f3aa to your computer and use it in GitHub Desktop.
$collection = app(Post::class);
//if tags
$collection = $collection->
whereHas('tags', function ($query) use ($t) {
$query->where('tag_id','=', $t);
});
//if languages
$collection = $collection->whereHas('languages', function ( $query ) use ( $l ){
$query->where('language_id', '=',$l);
});
//if search
$collection = $collection->where(function ($q) use ($search) {
$q->where('title', 'LIKE', '%' . $search . '%')
->orWhere('explanation','LIKE','%'.$search.'%')
->orWhere('usage','LIKE','%'.$search.'%')
->orWhere('codeexample','LIKE','%'.$search.'%')
->orderBy('id','desc');
});
//get all
$collection = $collection -> get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment