fomvasss / laravel-url-facet-filter

Building and displaying facet filter parameters and managing them

Stars
0

Laravel URL Facet Filter

License
Build Status
Latest Stable Version
Total Downloads
Quality Score

Building and displaying facet filter parameters and managing them


Installation

Run from the command line:

composer require fomvasss/laravel-url-facet-filter

Publishing

php artisan vendor:publish --provider="Fomvasss\UrlFacetFilter\ServiceProvider"

Usage

app/Http/Controllers/ProductControllr.php

<?php 

namespace App\Http\Controllers;

class ProductController extends Controller 
{
        public function index(Request $request)
        {
            $filterAttrs = \FacetFilter::toArray($request->get(\FacetFilter::getFilterUrlKey()));
            
            $products = Product::with('media')
                ->facetFilterable($filterAttrs) // facetFilterable - for example your scope
                ->get();

            return view('article.index', [
                'articles' => $products,
            ]);
        }  
}

Example, in url string:

https://my-site.com/products?⛃=length☛5⚬8♦serial☛master-lab♦ergonomic☛form-1⚬form-2

In php controller (after prepare FacetFilter::toArray()):

array:3 [▼
  "length" => array:2 [▼
    0 => "5"
    1 => "8"
  ]
  "serial" => array:1 [▼
    0 => "master-lab"
  ]
  "ergonomic" => array:2 [▼
    0 => "form-1"
    1 => "form-2"
  ]
]

Links