0

I have this query for Eloquent and for some reason it seems to be ignoring my last statement about only return dates that equal or greater then that date given.

$searchCriteriaArray is the array the key words I am search based on(this works)

$searchDate is the date I am filtering on (this does not work)

here is my query

$pool =User::select('id', 'email', 'updated_at', 'phone_number', 'headline','summary')
                    ->where(function ($query) use ($searchCriteriaArray){
                        for($i =0; $i < count($searchCriteriaArray); $i++){
                            $query->orwhere('headline', 'like', '%' . $searchCriteriaArray[$i] . '%' );
                        }
                    })->orWhere(function ($query) use ($searchCriteriaArray){
                        for($i =0; $i < count($searchCriteriaArray); $i++){
                            $query->orwhere('summary', 'like', '%' . $searchCriteriaArray[$i] . '%' );
                        }
                    })->where('updated_at', '>= ',$searchDate)
                    ->orderBy('updated_at', 'desc')
                    ->paginate(50);

I have looked as some other posts, including Laravel Eloquent compare date from datetime field. However this has not solved my problem. Why is Eloquent ignoring my last where statement and how do I fix this?

1
  • Can you double check what $searchDate actually holds? Commented Apr 26, 2018 at 0:40

1 Answer 1

0

Someone posted the answer and then deleted it. I needed to add this line

 ->where(function ($query) use ($searchDate){
                        $query->orwhere('updated_at', '>=', $searchDate);
                    })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.