You see, I have the table Photo, with these values:
Schema::create('fotos', function(Blueprint $table){
$table->increments('id');
$table->string('foto');
$table->string('nombre');
$table->date('fecha');
$table->unsignedInteger('user_id'); // Foraneo a la tabla User.
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
I have a form that modifies the data of the photo:
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header"><h1>Corregir información sobre la foto</h1></div>
<img class="card-img-top" src="{{url($f->ruta())}}"/>
<div class="card-body">
<form method="POST" action="{{route('foto.cambiar',$f)}}" enctype="multipart/form-data">
@csrf
<div class="form-group row">
<label for="nombre" class="col-md-4 col-form-label text-md-right">Nombre</label>
<div class="col-md-6">
<input id="nombre" type="text" class="form-control{{ $errors->has('nombre') ? ' is-invalid' : '' }}" name="nombre" value="{{ $f->nombre }}" required autofocus>
@if ($errors->has('nombre'))
<span class="invalid-feedback">
<strong>{{ $errors->first('nombre') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group row">
<label for="fecha" class="col-md-4 col-form-label text-md-right">Fecha en la que se creo la foto</label>
<div class="col-md-6">
<input id="fecha" type="date" class="form-control{{ $errors->has('fecha') ? ' is-invalid' : '' }}" name="fecha" value="{{ $f->fecha }}" required autofocus>
@if ($errors->has('fecha'))
<span class="invalid-feedback">
<strong>{{ $errors->first('fecha') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
Subir Foto
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
And it goes through this validator:
public function rules(){
return[
'nombre'=>'required',
'fecha'=>'required|before_or_equal:'.date('Y-m-d')
];
}
This checks that the date does not exceed the current one, but I want instead that the date does not exceed the value of created_at
.
How do I do that?