I have 2 forms, the first is the form formers
with 2 fields (name, firstname).
I also have the form trainings
with 2 fields (date_sitting, fk_former).
My problem, if I want to add an other sitting today (07/07/2019), I would like to see only the formers who have no training today.
Here, I retrieve a former who has a sitting today...
Do you think it's possible to get only the formers
who have no of sitting for now? It's annoying
In my Controller I have this:
Public function store(Request $request)
{
$request->validate([
'date_sitting' => 'required|date',
'fk_former' => 'required'
]);
$exists = Training::where('date_sitting', $request->get('date_sitting'))->where('fk_former', $request->get('fk_former'))->count();
if (!$exists){
Training::create($request->all());
return redirect()->route('trainings.index')
->with('success', 'new data created successfully');
}
else{
return redirect()->route('trainings.index')
->with('error', 'duplicata');
}
}
And in my create.blade.php I have this:
<div class="form-group ">
<label for="company-content">Name & Firstname </label>
<select name="fk_former" id="fk_former" class="form-control" required="required" value=""/>
<option value="">Choice former</option>
@foreach($formers as $former)
<option value="" >
</option>
@endforeach
{!! $errors->first('fk_former', '<span class="help-block">:message</span>') !!}
</select>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire