PHP code example of adtention / nova-datepicker-filter
1. Go to this page and download the library: Download adtention/nova-datepicker-filter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adtention / nova-datepicker-filter example snippets
namespace App\Nova\Filters;
use Adtention\DatepickerFilter\DatepickerFilter;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Laravel\Nova\Http\Requests\NovaRequest;
class CreatedAt extends DatepickerFilter
{
public function apply(NovaRequest $request, Builder $query, mixed $value): Builder
{
if (empty($value)) {
return $query;
}
return $query->whereDate('created_at', $value);
}
}
use App\Nova\Filters\CreatedAt;
public function filters(NovaRequest $request): array
{
return [
CreatedAt::make()
->single()
->placeholder('Created on')
->locale('en'),
];
}
namespace App\Nova\Filters;
use Adtention\DatepickerFilter\DatepickerFilter;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Laravel\Nova\Http\Requests\NovaRequest;
class CreatedBetween extends DatepickerFilter
{
public function apply(NovaRequest $request, Builder $query, mixed $value): Builder
{
[$from, $to] = is_array($value) ? $value : [null, null];
return $query
->when($from, fn (Builder $query) => $query->whereDate('created_at', '>=', $from))
->when($to, fn (Builder $query) => $query->whereDate('created_at', '<=', $to));
}
}