if the combination of teacher, subject, room, start time, end time and day is not in data base, it will get saved as a new schedule. Otherwise it will dd('Exist')
Also put a return statement after $schedule->save();
Have you given any thought to what you are trying to do?
What are the business rules ?
as @tykus says, what if you change the teacher on an existing schedule? Does that matter? Can you update the schedule with a different teacher? What if the teacher is on a completely different schedule at that time?
Same for the room?
You can create a duplicate if you just change the room? Is that ok?
These things you can test for in your logic They are not really validation concerns.
What i want to achieve is if you update a certain schedule and if the requests is already existing in the database it will not update hence, it will dd('something') thats what i want to achive in updating the schedule. Because the schedules table must have a different values in every fields in it. Becasuse for exampe. The room_1 is occupied in start_time = 2:30 and day = Monday-Friday and i add or update a schedule and put the same value then it must be not accepted. Also it applies to teachers and overall. Hope you understand what i mean sir @snapey@mohammed-h .
Your first query is checking only for that teacher in that room at that time on those days during that term of that school year (etc.). If your request data (for update) is changing any of those params, you will not find the existing Schedule.
You will need to separately check the availability of the teacher and the room.
basically i just dont want any duplicate values in my schedule table thats what i only want. If the schedule is click and there is no value changed in the form then if submit is clicked it will not update because it is existng,
:) To see if there is any schedule that matches, otherwise, you'll get the Query Builder object as result and that doesn't help :). You can also use count() instead of get()