Skip to content

Commit 710667f

Browse files
Merge pull request #9 from robbydooo/master
Adding with method
2 parents ac61c9d + c9727be commit 710667f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/macros.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,36 @@
4848
return $this;
4949
});
5050
}
51+
52+
if (! Builder::hasMacro('with')) {
53+
/**
54+
* Override the algolia search options to give you full control over the request,
55+
* similar to official algolia-laravel package.
56+
*
57+
* Adds the final missing piece to scout to make the library useful.
58+
*
59+
* @param array $opts Latitude of the center
60+
*
61+
* @return Laravel\Scout\Builder
62+
*/
63+
Builder::macro('with', function ($opts) {
64+
$callback = $this->callback;
65+
66+
$this->callback = function ($algolia, $query, $options) use ($opts, $callback) {
67+
$options = array_merge($options, $opts);
68+
69+
if ($callback) {
70+
return call_user_func(
71+
$callback,
72+
$algolia,
73+
$query,
74+
$options
75+
);
76+
}
77+
78+
return $algolia->search($query, $options);
79+
};
80+
81+
return $this;
82+
});
83+
}

0 commit comments

Comments
 (0)