check() ){ return abort(403); } $morph = $request->input('morph', Product::class); $q = '%' . $request->input('q') . '%'; switch ($morph) { case Product::class: $q = Product::where('name', 'LIKE', $q) ->orWhere('description', 'LIKE', $q); break; case Post::class: $q = Post::where('title', 'LIKE', $q) ->orWhere('subtitle', 'LIKE', $q) ->orWhere('body', 'LIKE', $q); break; case Group::class: $q = Group::where('name', 'LIKE', $q) ->orWhere('subtitle', 'LIKE', $q) ->orWhere('description', 'LIKE', $q); break; case Category::class: $q = Category::where('name', 'LIKE', $q) ->orWhere('subtitle', 'LIKE', $q) ->orWhere('description', 'LIKE', $q); break; case Clip::class: $q = Clip::where('title', 'LIKE', $q) ->orWhere('body', 'LIKE', $q); break; case Gallery::class: $q = Gallery::where('title', 'LIKE', $q) ->orWhere('description', 'LIKE', $q); break; default: return ['OK' => false, 'error' => __("Invalid morph")]; } return ['OK' => true, 'data' => $q->orderByDesc('updated_at')->limit($this->limit)->get()]; } }