0

I am using laravel 5.5 and checking event checking if slot available between 2 times using this query:

$schedules->where('id', $id)
                ->wherebetween($date, ['start','end'])
                ->orwherebetween($endTime, ['start','end'])
                ->orwherebetween('start', [$date,$endTime])
                ->orderBy('start')->get(); 

getting this error

"message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column '2019-03-06 13:00:00' in 'where clause'

1
  • Use whereRaw() Commented Mar 8, 2019 at 5:34

2 Answers 2

2

its because the 1st parameter should be the name of the column:

you should change your code to:

->wherebetween('column name', ['1st date','2nd date'])
->orwherebetween('column name', ['1st date','2nd date'])
Sign up to request clarification or add additional context in comments.

Comments

-1

I have fixed that by adding DB::raw() read more

$schedules->where('id', $id)
                ->wherebetween(DB::raw($date), ['start','end'])
                ->orwherebetween(DB::raw($endTime), ['start','end'])
                ->orwherebetween('start', [$date,$endTime])
                ->orderBy('start')->get(); 

1 Comment

Unless you have columns names as dates I'm pretty much sure you can just keep the last orWhereBetween (changed to whereBetween) and have the same result

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.