alvaro-canepa/oc-trait-scope-frontend

OctoberCMS Frontend scope trait

1.0.1 2019-08-26 21:26 UTC

This package is auto-updated.

Last update: 2024-11-27 09:14:55 UTC


README

OctoberCMS Frontend scope trait

Installation

Package requires PHP 7.2+ and works with OctoberCMS.

Require the package in your composer.json:

    "require": {
        ...
        "alvaro-canepa/oc-trait-scope-frontend": "~1.0",
    },

Usage example

    class myModel extend Model {
        use PlanetaDelEste\Traits\ScopeFrontendTrait;

        ...
    }

    /*
     * @var array $sort 'column' key must be the model column to sort
     *                  'direction', accepted values: "asc", "desc"
     */
    $sort = [
                'column'    => get('sort.column'),
                'direction' => get('sort.direction')
            ];
    /*
     * @var array $filters key => value format, where key was used as column name, 
     *                     and value as search term.
     */
    $filters = get('filters');

    $collection = myModel::frontend($filters, $sort)->get();