Actually, I have the solution, but I want to know if there is any more efficient solution. What I need are the events that have not yet expired so to speak. Inside a base with all the events.
Basically what I do is get the events with an OrderBy starting from the date ascending and then I go through, comparing with the current one, taking out the minor ones. And staying with those that exceed the current date.
I wanted to know if somehow, from a controller or a composer, I can get the list with the date I need from the beginning, without using the foreach. It would be neat, or efficient as well, to somehow enter a query to the database here
public function compose(View $view)
{
$categorias= Categoria::orderBy('nombre','asc')->get();
$tags= Tag::orderBy('nombre','asc')->get();
$eventos= Evento::orderBy('fecha','asc')->get();
foreach ($eventos as $key => $evento) {
if ($evento->fecha <= Carbon::now()) {
unset($eventos[$key]);
}
}
$view
->with('categorias', $categorias)
->with('eventos',$eventos)
->with('tags',$tags);
}
I answer myself in case it helps someone else later.
In this way, we release the foreach and it already brings us a collection with the events with the restriction that I needed