| @@ -23,9 +23,8 @@ | ||
| 23 | 23 | |
| 24 | 24 | protected $searchable = ['title', 'description']; |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * Local scope to filter products by search/query string | |
| 28 | 27 | * @param ModelQueryBuilder $query |
| 29 | 28 | * @param string $search |
| 30 | 29 | * @return ModelQueryBuilder |
| 31 | 30 | */ |
| @@ -46,9 +45,17 @@ | ||
| 46 | 45 | return $query; |
| 47 | 46 | } |
| 48 | 47 | |
| 49 | 48 | /** |
| 50 | - * This `getProducts` method will return the list of products | |
| 49 | + * @param $query | |
| 50 | + * @return mixed | |
| 51 | + */ | |
| 52 | + public function scopeOrderedByTitle($query) | |
| 53 | + { | |
| 54 | + return $query->orderBy('title', 'ASC'); | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 51 | 58 | * @param string $search |
| 52 | 59 | * @return array |
| 53 | 60 | */ |
| 54 | 61 | public function getProducts ( $search ) |
| @@ -53,14 +60,13 @@ | ||
| 53 | 60 | */ |
| 54 | 61 | public function getProducts ( $search ) |
| 55 | 62 | { |
| 56 | 63 | return [ |
| 57 | - 'products' => $this->orderBy('id', 'DESC')->searchBy($search)->paginate() | |
| 64 | + 'products' => $this->orderedByTitle()->searchBy($search)->paginate() | |
| 58 | 65 | ]; |
| 59 | 66 | } |
| 60 | 67 | |
| 61 | 68 | /** |
| 62 | - * This `getProduct` method will get product by id and return | |
| 63 | 69 | * @param int $productId |
| 64 | 70 | * @return array |
| 65 | 71 | */ |
| 66 | 72 | public function getProduct ( $productId ) |
| @@ -70,9 +76,8 @@ | ||
| 70 | 76 | ]; |
| 71 | 77 | } |
| 72 | 78 | |
| 73 | 79 | /** |
| 74 | - * This `createProduct` method will create a new product | |
| 75 | 80 | * @param array $data |
| 76 | 81 | * @return array |
| 77 | 82 | */ |
| 78 | 83 | public function createProduct ( $data ) |
| @@ -86,9 +91,8 @@ | ||
| 86 | 91 | ]; |
| 87 | 92 | } |
| 88 | 93 | |
| 89 | 94 | /** |
| 90 | - * This `updateProduct` method will update an exiting product by id | |
| 91 | 95 | * @param int $productId |
| 92 | 96 | * @param array $data |
| 93 | 97 | * @return array |
| 94 | 98 | */ |
| @@ -105,9 +109,8 @@ | ||
| 105 | 109 | ]; |
| 106 | 110 | } |
| 107 | 111 | |
| 108 | 112 | /** |
| 109 | - * This `deleteProduct` method will delete an exiting product by id | |
| 110 | 113 | * @param int $productId |
| 111 | 114 | * @return array |
| 112 | 115 | */ |
| 113 | 116 | public function deleteProduct ( $productId ) |