You see, I have an Offer table with these columns:
Schema::create('ofertas', function (Blueprint $table){
$table->increments('id');
$table->string('titulo');
$table->text('descripcion');
$table->string('empresa');
$table->string('sector');
$table->date('fecha_limite');
$table->timestamps();
});
Also, it has this function in Oferta.php:
public function caducado(){
return strtotime($this->fecha_limite)<strtotime(date("d-m-Y")); // Si devuelve verdadero, es que la oferta ha caducado al pasar la fecha limite.
}
This checks if the deadline for the offer has passed, or not yet. I want to use it to filter a list of offers in OfertaController.php:
public function filtrar(){
$ofertas=Oferta::all()->where('caducado',false);
return view('listas.ofertas',compact('ofertas'));
}
But I get this: Call to undefined function App\Http\Controllers\caducado()
How do I request it?
Edit: I know that to summon the method of a table I can not make $ offer-> expired, but $oferta->caducado()
. The question is what the homologo would be in where()
.
PS: Seeing that it is not possible to use the function, I used this code:
public function filtrar(){
$ofertas=Oferta::all()->where(strtotime('fecha_limite'),'<',strtotime(date("d-m-Y")));
return view('listas.ofertas',compact('ofertas'));
}
The problem that I find now is that I have 2 offers: One with a date of 2018-05-01
(this expired) and another one of 2018-05-15
(it has not expired yet). It is assumed that the 2nd offer will be shown, but not the 1st one, since it is already expired, but guess: