lundi 27 juin 2016

Custom function on model

I have a query like this:

$results = User::where('gender', 'male')
    ->get();

Is there a way that I can call a custom function on this query, like:

$results = User::where('gender', 'male')
    ->get()
    ->split();

Where split() would be the following function:

public function split() {
    return array_chunk($results->toArray(), 10);
}

How would I implement something like this? Where would the function go?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire