| @@ -46,8 +46,18 @@ | ||
| 46 | 46 | return $query; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | + * Local scope to order products alphabetically by title | |
| 51 | + * @param $query | |
| 52 | + * @return mixed | |
| 53 | + */ | |
| 54 | + public function scopeOrderedByTitle($query) | |
| 55 | + { | |
| 56 | + return $query->orderBy('title', 'ASC'); | |
| 57 | + } | |
| 58 | + | |
| 59 | + /** | |
| 50 | 60 | * This `getProducts` method will return the list of products |
| 51 | 61 | * @param string $search |
| 52 | 62 | * @return array |
| 53 | 63 | */ |
| @@ -53,9 +63,9 @@ | ||
| 53 | 63 | */ |
| 54 | 64 | public function getProducts ( $search ) |
| 55 | 65 | { |
| 56 | 66 | return [ |
| 57 | - 'products' => $this->orderBy('id', 'DESC')->searchBy($search)->paginate() | |
| 67 | + 'products' => $this->orderedByTitle()->searchBy($search)->paginate() | |
| 58 | 68 | ]; |
| 59 | 69 | } |
| 60 | 70 | |
| 61 | 71 | /** |