vyuldashev/nova-column-filter

A Laravel Nova database column filter.

v1.0.0 2019-04-07 22:46 UTC

This package is auto-updated.

Last update: 2024-11-07 11:02:35 UTC


README

Latest Version on Packagist Total Downloads

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require vyuldashev/nova-column-filter

Usage

Simple filter using equals constraint:

<?php

declare(strict_types=1);

namespace App\Nova\Filters;

use Vyuldashev\NovaColumnFilter\ColumnFilter;

class EmailFilter extends ColumnFilter
{
    public $name = 'Email';
    public $column = 'email';
}

Advanced filter with custom query:

<?php

declare(strict_types=1);

namespace App\Nova\Filters;

use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Laravel\Nova\Filters\DateFilter;

class CreatedAtFromFilter extends DateFilter
{
    public $name = 'Created at from';

    public function apply(Request $request, $query, $value): object
    {
        $value = Carbon::parse($value);

        return $query->where('created_at', '>=', $value->startOfDay());
    }
}