I have a table called Input, which has these parameters:
public function up(){
Schema::create('entradas', function (Blueprint $table){
$table->increments('id');
$table->date('fecha');
$table->unsignedInteger('persona'); // Quien ha comprado la entrada.
$table->foreign('persona')->references('id')->on('users');
$table->timestamps();
});
}
I want to make a form to create an entry, but with the rule that the date for which it is reserved can not be earlier than the current one.
@extends('layouts.app')
@section('content')
@Logged()
@include('partials.errors')
<div align="center" class="panel panel-default">
<h1 class="text-center text-mute"> {{ __("Nueva reserva") }} </h1>
</div>
<div class="row">
<form method="POST" action="../reserva">
{{ csrf_field() }}
<div class="form-group">
<label for="fecha" class="col-md-12 control-label"> {{ __("Indique la fecha") }}
</label>
<input id="fecha" style="width:150px" type="date" class="form-control" name="fecha" value="{{ old('fecha') }}"/>
</div>
<button type="submit" name="addPlanta" class="btn btn-default"> {{ __("Reservar entrada") }}
</button>
</form>
</div>
@else
<h1 class="text-center text-mute" style="color:#FF0000"> {{ __("Debes haber iniciado sesión para crear una reserva") }} </h1>
@endLogged
@endsection
web.php:
Route::post('reserva','EntradaController@confirmar');
And here where the reservation will be validated:
public function confirmar(Request $request){
$normas=[
'fecha' => 'required',
];
$this->validate($request,$normas);
if(Auth::user()->saldo<7)
return back()->with('message', ['msg', __('No tienes suficiente dinero')]);
else{
$hoy=new DateTime("now");
if($request->fecha>=$hoy){
$request->merge(['persona' => auth()->id()]);
Entrada::create($request->all());
Auth::user()->saldo-=7;
return back()->with('message', ['success', __('Reserva realizada con exito')]);
}
else
return back()->with('message', ['msg', __('No puede reservar para una fecha pasada')]);
}
}
}
And to my surprise, regardless of whether the date chosen is greater or less than the current one, I always get the error message because the date chosen is earlier than the current one. Now check with dd () the dates variables and although the current date gives more information (hours, minutes, etc) than the date of the form, both dates are. Should I change the format of the dates?
Edit: I've already made the comparison, but I run into this error message:
I have verified that it happens right in the Input :: create (). What will it fail now?