Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

filter from taggable laravel

$searchdata = ['A','B']; //keep it as an array
if(count($searchdata) > 1) {
    $data = User::with('tags')
                      ->orWhereHas('tags', function($q) use ($searchdata){
                            $q->whereIn('name', $searchdata);
                      })->get();

} else {
    $data = User::with('tags')
                      ->orWhereHas('tags', function($q) use ($searchdata){
                            $q->where('name', 'LIKE', '%' . $searchdata[0] . '%');
                       })->get();

}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #filter #taggable #laravel
ADD COMMENT
Topic
Name
5+5 =