Reputation: 2233
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)
->exists();
if($timeExists){
return redirect('allocateRoomPage')->withErrors(['time' => 'Class Room Already Taken']);
}
$classRoom = new ClassRoom();
$classRoom->department_id=$request->input('department_id');
$classRoom->room_id=$request->input('room_id');
$classRoom->course_id=$request->input('course_id');
$classRoom->day_id=$dayId;
$classRoom->start=$startTime;
$classRoom->end=$endTime;
$classRoom->save();
$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.
Upvotes: 1
Views: 2010
Reputation: 1428
Simply use
$timeExists = ClassRoom::where('day_id', $dayId)
->Where('start', $startTime)
->Where('end', $endTime)
->exists();
as there is no andWhere method in laravel
Upvotes: 1
Reputation: 5324
There is no andWhere
method.
Simple where(<...>)->where(<...>)
acts like where <...> and where <...>
.
Upvotes: 1