I have a problem concerning the checking of my dates.
Example, my motorbike number 000001 is in revision from 30/08/2019 to 03/09/2019. The recording is good. (no problem)
However, if I add a revision on 02/09/2019 to 03/09/2019, I would like to add an error message explaining that the motorbike is already in revision.
My function index() is like this:
$revisionId = Revision::whereDate('date_revision_start', "<=" , $now)
->whereDate('date_revision_end', ">=", $now)
->pluck('fk_motorbike')->toArray();
I think my problem is in my function store()???
public function store(Request $request)
{
$exists = Motorbike::where('matriculation', $request->get('matriculation'))->where('number_motorbike', $request->get('number_motorbike'))->where('status', $request->get('status'))->count();
if (!$exists){
$revisions = Revision::??????
if (!$exists){
Motorbike::create($request->all());
return redirect()->route('motorbikes.index')
->with('success', 'new data created successfully');
}
else{
return redirect()->route('motorbikes.index')
->with('error', 'duplicate');
}
}
}
Class Motorbike
class Motorbike extends Model
{
//
protected $fillable = ['matriculation', 'number_motorbike', 'status'];
etc...
Class Revision
class Revision extends Model
{
//
protected $fillable = ['date_revision_start', 'date_revision_end', 'garage', 'fk_motorbike'];
Thank you for your help
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2HDhZsS
via IFTTT
Aucun commentaire:
Enregistrer un commentaire