LaravelPackages.net
Acme Inc.
Toggle sidebar
fomvasss/laravel-url-facet-filter

Building and displaying facet filter parameters and managing them

394
2
1.8.0
About fomvasss/laravel-url-facet-filter

fomvasss/laravel-url-facet-filter is a Laravel package for building and displaying facet filter parameters and managing them. It currently has 2 GitHub stars and 394 downloads on Packagist (latest version 1.8.0). Install it with composer require fomvasss/laravel-url-facet-filter. Discover more Laravel packages by fomvasss or browse all Laravel packages to compare alternatives.

Last updated

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

Build url`s

<a href="{{ \FacetFilter::build('color', 'red') }}">Red</a>	
<a href="{{ \FacetFilter::build('color', 'green') }}">Green</a>	
<a href="{{ \FacetFilter::build('size', 'm') }}">M</a>	
<a href="{{ \FacetFilter::build('size', 'xl') }}">XL</a>	

Usage in controller

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?⛃=color☛red⚬green♦size☛m♦ergonomic☛form-1⚬form-2

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

array:3 [▼
  "color" => array:2 [▼
    0 => "red"
    1 => "green"
  ]
  "size" => array:1 [▼
    0 => "m"
  ]
  "ergonomic" => array:2 [▼
    0 => "form-1"
    1 => "form-2"
  ]
]

Star History Chart