Oihana PHP

SortAfterTrait

Sorts a collection on a nested property declared by the model's `sortable.after` definition.

When the bound model exposes a sortable['after'] entry formatted as "relation.property", this trait reorders the given items in ascending order on that nested property ($item->relation->property). If no such definition exists, the items are returned unchanged.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Methods

sortAfter()  : mixed
Sorts the given items on the nested property defined by the model's `sortable.after` setting.

Methods

sortAfter()

Sorts the given items on the nested property defined by the model's `sortable.after` setting.

public sortAfter(mixed $items) : mixed

The after definition is expected to be a dot-separated "relation.property" string; the items are compared with strcmp() on $item->relation->property. When the model has no usable after definition, the items are returned as-is.

Parameters
$items : mixed

The collection of items (objects) to sort.

Return values
mixed

The sorted collection, or the original collection when no sort is applied.

On this page

Search results