Issue :
I'm trying to get multiple keywords searched in a single query, but for some reason I'm getting this error always :
[2020-08-29 03:50:02] development.ERROR: Class 'App\Http\Controllers\API\Post' not found {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Class 'App\\Http\\Controllers\\API\\Post' not found at /home2/examplehat/public_html/shopper/app/Http/Controllers/API/ClassifiedSearchAPIController.php:78)
[stacktrace]
Here's my controller's index function :
public function index(Request $request)
{
try{
$this->productRepository->pushCriteria(new RequestCriteria($request));
$this->productRepository->pushCriteria(new LimitOffsetCriteria($request));
$this->productRepository->pushCriteria(new ProductsOfFieldsCriteria($request));
if($request->get('trending',null) == 'week'){
$this->productRepository->pushCriteria(new TrendingWeekCriteria($request));
}
else{
$this->productRepository->pushCriteria(new NearCriteria($request));
}
// $this->productRepository->orderBy('closed');
// $this->productRepository->orderBy('area');
$queryString = $request->query;
$terms = explode(" ", request('q'));
if ($queryString = $request->query('search')) {
// [$column, $term] = explode(':', $queryString);
$products = Post::query() //----PROBLEM HERE
->whereHas('name', function ($query) use ($terms) {
foreach ($terms as $term) {
// Loop over the terms and do a search for each.
$query->where('name', 'like', '%' . $term . '%');
}
})->get();
// $products = Product::where('name', 'like', '%' . $term . '%')->get();
}
else
$products = $this->productRepository->all();
// $products = Product::where('name', 'like', '%' . 'chilli' . '%')->get();
} catch (RepositoryException $e) {
return $this->sendError($e->getMessage());
}
return $this->sendResponse($products->toArray(), 'Products retrieved successfully');
}
Can someone please help me understand what needs to be done to fix the error stated ? I tried use App\Post;
but it didn't help.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/31CNEEV
via IFTTT
Aucun commentaire:
Enregistrer un commentaire