¨4.0.1¨
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
|
||||
namespace Modules\Product\Http\Controllers;
|
||||
|
||||
use Closure;
|
||||
use Modules\Product\Entities\Product;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\Product\Http\Response\SuggestionsResponse;
|
||||
|
||||
class SuggestionController
|
||||
@@ -11,9 +13,9 @@ class SuggestionController
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return SuggestionsResponse
|
||||
*/
|
||||
public function index(Product $model)
|
||||
public function index(Product $model): SuggestionsResponse
|
||||
{
|
||||
$products = $this->getProducts($model);
|
||||
|
||||
@@ -25,25 +27,13 @@ class SuggestionController
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total results count.
|
||||
*
|
||||
* @param \Modules\Product\Entities\Product $model
|
||||
* @return int
|
||||
*/
|
||||
private function getTotalResults(Product $model)
|
||||
{
|
||||
return $model->search(request('query'))
|
||||
->query()
|
||||
->when(request()->filled('category'), $this->categoryQuery())
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get products suggestions.
|
||||
*
|
||||
* @param \Modules\Product\Entities\Product $model
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
* @param Product $model
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function getProducts(Product $model)
|
||||
{
|
||||
@@ -67,10 +57,11 @@ class SuggestionController
|
||||
->get();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns categories condition closure.
|
||||
*
|
||||
* @return \Closure
|
||||
* @return Closure
|
||||
*/
|
||||
private function categoryQuery()
|
||||
{
|
||||
@@ -80,4 +71,20 @@ class SuggestionController
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get totalPrice results count.
|
||||
*
|
||||
* @param Product $model
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function getTotalResults(Product $model): int
|
||||
{
|
||||
return $model->search(request('query'))
|
||||
->query()
|
||||
->when(request()->filled('category'), $this->categoryQuery())
|
||||
->count();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user