x69 x69 - 5 months ago 27
SQL Question

Laravel Query: BadMethodCallException in Builder.php line 2258:

I have building a laravel application where in a controller I'm checking with time overlapping problem.

The Logic I have used is in my controller's query first I will check whether the day_id has given as input is match with database with that day_id and then it will check with the time, if it matches so it can't let user to save the input otherwise if the query failed, it will let user to save the data.

public function postAllocateRoom(Request $request)

$startTime = Carbon::parse(str_replace(array('am', 'pm'), ':00', $request->input('start')));
$endTime = Carbon::parse(str_replace(array('am', 'pm'), ':00', $request->input('end')));
$dayId = $request->input('day_id');

$timeExists = ClassRoom::where('day_id', $dayId)
->andWhere('start', $startTime)
->andWhere('end', $endTime)

return redirect('allocateRoomPage')->withErrors(['time' => 'Class Room Already Taken']);

$classRoom = new ClassRoom();

$request->session()->flash('success', 'Successfully allocated room');

return redirect('allocateRoomPage');


But After I run the program I'm seeing the following Error:

BadMethodCallException in Builder.php line 2258: Call to undefined
method Illuminate\Database\Query\Builder::andWhere()

If anyone find the problem please help me to find the solution.


Simply use

 $timeExists = ClassRoom::where('day_id', $dayId)
                                            ->Where('start', $startTime)
                                            ->Where('end', $endTime)

as there is no andWhere method in laravel