/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle(Search $search)
 {
     $table = $this->argument('table');
     $collection = collect(DB::table($table)->get())->map(function ($collect) {
         $collect->objectID = $collect->id;
         return (array) $collect;
     });
     $search->index($table)->saveObjects($collection);
     $this->info('All Done!');
 }
 /**
  * @SWG\Get(
  *     path="/book/search",
  *     summary="Search by ISBN",
  *     description="Return Book Prices",
  *     operationId="search",
  *     tags={"book"},
  *     produces={"application/json"},
  *     @SWG\Parameter(
  *         name="q",
  *         in="query",
  *         description="Single ISBN or ISBNs with comma ",
  *         required=true,
  *         type="string"
  *     ),
  *     @SWG\Response(response="200", description="Error Messages or Book Objects")
  * )
  */
 public function search(Search $search, Request $request)
 {
     // validate query
     $validator = Validator::make($request->all(), ['q' => 'bail|required|max:255']);
     if ($validator->fails()) {
         return response()->json(['errors' => $validator->errors()->all()]);
     }
     $q = $request->input('q');
     $result = $search->get($q);
     if (empty($result)) {
         return response()->json(['errors' => ['We didn\'t find any books that matched your search.']]);
     }
     return response()->json($result);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle(Search $search)
 {
     // fetch all recipes
     $recipes = collect(\DB::table('recipes')->where('is_master', '=', 1)->get())->map(function ($recipe) {
         $ingredients = collect(\DB::table('recipe_ingredients')->select('ingredients.*')->join('ingredients', 'recipe_ingredients.ingredient_id', '=', 'ingredients.id')->where('recipe_ingredients.recipe_id', '=', $recipe->id)->get())->map(function ($ingredient) {
             return $ingredient->name;
         })->toArray();
         return ['objectID' => $recipe->id, 'name' => $recipe->name, 'slug' => $recipe->slug, 'ingredients' => implode(',', $ingredients)];
     });
     $batch = array();
     foreach ($recipes as $recipe) {
         array_push($batch, $recipe);
         if (count($batch) == 1000) {
             $search->index('recipes')->saveObjects($batch);
             $batch = array();
         }
     }
     // save objects
     $search->index('recipes')->saveObjects($batch);
     // completion message
     $this->info('All Done');
 }
 public function getAlgoliaSearch(Search $search, Request $request)
 {
     $results = $search->index('xxxxxxxxxx')->get($request->name);
     return $results;
     $number2word = new NumberFormatter("en", NumberFormatter::SPELLOUT);
     return ucwords($number2word->format(5650)) . ' Only';
     $user = User::find($id = 3);
     //\Event::fire(new UserWasBanned($user));
     event(new UserWasBanned($user));
     return $user->toArray();
 }