PHP code example of marshmallow / nova-global-filter

1. Go to this page and download the library: Download marshmallow/nova-global-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/ */

    

marshmallow / nova-global-filter example snippets


...
use Nemrutco\NovaGlobalFilter\NovaGlobalFilter;
use App\Nova\Filters\Date;

class Store extends Resource
{
  ...
  public function cards(Request $request)
  {
    return [
      new TotalSales // Value Metric

      new Orders, // Trend Metric

      new MostSoldProduct, // Partition Metric

      // NovaGlobalFilter
      new NovaGlobalFilter([
        new Date, // Date Filter
      ]),
    ];
  }
  ...
}

use Nemrutco\NovaGlobalFilter\GlobalFilterable;
use App\Nova\Filters\Date;
...

class UsersPerDay extends Trend
{
use GlobalFilterable;

  public function calculate(NovaRequest $request)
  {
    // Filter your model with existing filters
    $model = $this->globalFiltered(Store::class,[
      Date::class // DateFilter
    ]);

    // Do your thing with the filtered $model
    return $this->countByDays($request, $model);

  }
...
}

...
// set default date
public function default()
{
    return Carbon::now();
}
...

...
new NovaGlobalFilter([
    // Filters
])->inline(),
...

...
new NovaGlobalFilter([
    // Filters
])->resettable(),
...

...
new NovaGlobalFilter([
    // Filters
])->inline()->resettable(),

new NovaGlobalFilter([
    // Filters
])->onlyOnDetail(),
...
js
...
  Nova.$emit("global-filter-request");
...
js
...
created() {
  Nova.$emit("global-filter-request", [
      "App\\Nova\\Filters\\DateFilter",
      "App\\Nova\\Filters\\CountryFilter"
  ]);
},
...