vendredi 25 décembre 2015

Combining relationship sorting and filtering

I have two models: Item and Category. The Item model has a category_id field which is a foreign key of the category.

On the search page I am currently performing filtering. This is done via a series of where() clauses, for example

if($request->input('location_id', "") != "") {
    $query->where('location_id', '=', $request->input('location_id'));
}

These are contained within the scope search(), so they are called like this:

$results = Item::search($request)->get();

I now want to apply sorting to the results, firstly by the name column of the category, then by the product_number column on the items table.

How would I go about doing this without interfering with the filtering in the search scope?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire