public function show($id) { $product = \App\Models\Product::query()->with(['seller' => function ($q) { $q->select('id', 'username'); }, 'categories'])->find($id); if ($userAuth = \Auth::user()) { \App\Models\Product::setFavourites(collect([$product]), $userAuth); } return $product ?: $this->notFoundJson(); }
public function search($input) { $query = Product::query(); $columns = Schema::getColumnListing('products'); $attributes = array(); foreach ($columns as $attribute) { if (isset($input[$attribute]) and !empty($input[$attribute])) { $query->where($attribute, $input[$attribute]); $attributes[$attribute] = $input[$attribute]; } else { $attributes[$attribute] = null; } } return [$query->get(), $attributes]; }
public function view($id) { return Product::query()->find($id); }