I have in fact 3 forms:
The first is students with 2 fields (name, firstname).
The second is trainings with 2 fields (date_sitting, fk_student)`.
The next is the form observations with 3 fields (title, description, fk_student).
My problem is that I can add 2 dates sittings for 1 observation for the same date.
Is it it's possible to make a blocking for this genre of case?
Here is an idea of my code so far:
public function store(Request $request)
{
$request->validate([
'title' => 'required|string|max:30',
'description' => 'required|string|max:80',
'fk_student' => 'required'
]);
$exists = Observation::where('title', $request->get('title'))->where('description', $request->get('description'))->where('fk_student', $request->get('fk_student'))->count();
if (!$exists){
$sittings = Training::where('fk_student', $request->get('fk_student'))->first();
if(!isset($sittings)){ // No payment = block creation and return error msg.
return redirect()->route('observations.index')
->with('error', 'No sitting, no observation for you!');
}
else{
Observation::create($request->all());
return redirect()->route('observations.index')
->with('success', 'new data created successfully');
}
}
if(isset($exists)){
return redirect()->route('observations.index')
->with('error', 'Duplicate ! ');
}
}
Thank you for your help.
via Chebli Mohamed


Aucun commentaire:
Enregistrer un commentaire