|
@@ -0,0 +1,37 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Providers\Macros;
|
|
|
+
|
|
|
+use Illuminate\Database\Eloquent\Builder;
|
|
|
+use Illuminate\Support\ServiceProvider;
|
|
|
+
|
|
|
+class BuilderProvider extends ServiceProvider
|
|
|
+{
|
|
|
+
|
|
|
+ * Register services.
|
|
|
+ */
|
|
|
+ public function register(): void
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Bootstrap services.
|
|
|
+ */
|
|
|
+ public function boot(): void
|
|
|
+ {
|
|
|
+
|
|
|
+ * Case sensitive search
|
|
|
+ */
|
|
|
+ Builder::macro('whereLike', function (string $attribute, string $searchTerm) {
|
|
|
+ return $this->orWhere($attribute, 'LIKE', $searchTerm);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ * Case in-sensitive search
|
|
|
+ */
|
|
|
+ Builder::macro('whereILike', function (string $attribute, string $searchTerm) {
|
|
|
+ return $this->orWhere($attribute, 'ILIKE', $searchTerm);
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|