Skip to content
filters / 1

Installation & Setup

Last updated:

On this page

Installing

Filters and its Javaabu dependencies aren't on Packagist yet. Add their repositories, then require the package:

"repositories": [
    { "type": "vcs", "url": "https://github.com/Javaabu/filters" },
    { "type": "vcs", "url": "https://github.com/Javaabu/stencil" },
    { "type": "vcs", "url": "https://github.com/Javaabu/forms" },
    { "type": "vcs", "url": "https://github.com/Javaabu/manifest" }
]
composer require javaabu/filters:^1.0@dev

The service provider registers itself. There's nothing to configure for the common case: filters read the current request's query string, and {{ $filters }} renders the filter bar with javaabu/forms.

Inertia React

The React components are in the Composer package, under resources/js, and your app builds them with its own Vite through javaabu/manifest, the same way as stencil's renderer. If your app already renders stencil forms in React, there's nothing more to do. Otherwise add manifest's Vite plugin:

// vite.config.js
import { defineConfig } from "vite"
import laravel from "laravel-vite-plugin"
import react from "@vitejs/plugin-react"
import manifest from "./vendor/javaabu/manifest/dist/vite.js"

export default defineConfig({
  plugins: [laravel({ input: ["resources/js/app.tsx"] }), react(), manifest()],
})

Install what the components import (php artisan manifest:check lists it, with the command for your package manager), and set up FormsProvider once with the Inertia router, so the filter form submits as an Inertia visit and links navigate without a reload:

npm install github:Javaabu/react-forms#next-gen react react-dom
php artisan manifest:check     # checks React packages once @inertiajs/react is installed, or with --scope=pages
php artisan manifest:types     # TypeScript paths for @javaabu/filters and @javaabu/stencil
// resources/js/app.tsx
import { createInertiaApp } from "@inertiajs/react"
import { createRoot } from "react-dom/client"
import { FormsProvider, mergeAdapters } from "@javaabu/forms"
import { inertia, inertiaLinks } from "@javaabu/forms/inertia"
import { onu } from "@javaabu/forms/onu"

const ui = mergeAdapters(onu, inertiaLinks)

createInertiaApp({
  resolve: (name) => import(`./pages/${name}.tsx`),
  setup({ el, App, props }) {
    createRoot(el).render(
      <FormsProvider ui={ui} router={inertia}>
        <App {...props} />
      </FormsProvider>,
    )
  },
})

Filters declares @javaabu/forms, react and react-dom for pages only, so manifest:check in a Blade-only app doesn't ask for them.

Then import the components:

import { FilterBar, SortableHeading, type FiltersData } from "@javaabu/filters"

Publishing

Everything has a default; publish only what you change:

php artisan vendor:publish --tag=filters-config         # config/filters.php
php artisan vendor:publish --tag=filters-translations   # lang/vendor/filters
php artisan vendor:publish --tag=filters-views          # resources/views/vendor/filters

React components are overridden through manifest: see Customizing views.

Documentation
All packages

javaabu/filters

Source on GitHub