Ahmed Karmous
Ahmed Karmous

Reputation: 373

laravel eloquent search a word in a database row

hi im making an application in laravel i have a search field that i need to find a word i a sentence exemple

in the table i have the field question

so when i enter "Lequel" it give me "Lequel de ces animaux n'est pas un singe?"

but the thins is that in eloquent there is like but it don't give me the result i have to enter the whole sentence to find it

    $questions = DB::table('geolocalizedQuestion')
                                    ->where('theme','LIKE',$the)
                                    ->orWhere('question','LIKE',$quest)
                                    ->paginate(10); 

                            return View::make('home.home')
                            ->with('user', Auth::user())
                            ->with('theme', $theme)
                            ->with('the' ,  $the)
                            ->with('questions',$questions);

is there any suggestion for help :) thx

Upvotes: 0

Views: 3421

Answers (2)

sheepy
sheepy

Reputation: 56

$the, $quest is the string what is looking for, then you need add to you query a '%value%' to containing rows

$the = "%$the%";
$quest = "%$quest%";

more info here

Upvotes: 1

xdazz
xdazz

Reputation: 160833

Have you missed the %?

$questions = DB::table('geolocalizedQuestion')
                                ->where('theme', 'LIKE', '%'.$the.'%')
                                ->orWhere('question', 'LIKE', '%'.$quest.'%')
                                ->paginate(10); 

Upvotes: 2

Related Questions