Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Laurent_awkn's avatar

Substract date to current date into nova

0

Would someone convert this code to nova:

Training::where( 'created_at', '>', Carbon::now()->subDays(1)) ->get()

thanks in advance,

0 likes
3 replies
bugsysha's avatar
bugsysha
Best Answer
Level 61

You can use indexQuery to limit your results in Nova. If you gave more info maybe better approach can be suggested.

1 like
Laurent_awkn's avatar

Thanks @bugsysha this is exactly what I needed. I still wonder how you could understand my desperate, succinct question :-) For further readers : I wanted to create a tailor-made resource (based on one of my app model called Training) I ended up with : in the tailormade resource nova\new_training.php :

/** * The model the resource corresponds to. * * @var string */ public static $model = 'App\Training';

/**
 * Build an "index" query for the given resource.
 *
 * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
 * @param  \Illuminate\Database\Eloquent\Builder  $query
 * @return \Illuminate\Database\Eloquent\Builder
 */
public static function indexQuery(NovaRequest $request, $query)
{
    return $query->where('created_at', '>',Carbon::now()->subDays(1));
}

Thanks again :-)

bugsysha's avatar

Thanks @bugsysha this is exactly what I needed.

You are very welcome. Thanks for the "best answer" :)

I still wonder how you could understand my desperate, succinct question :-)

That is exactly why I'm here. I'm trying to improve my understanding of junior developers as well as my English overall.

Please or to participate in this conversation.