diff --git a/pint.json b/pint.json index fb5bab881..131eea8f5 100644 --- a/pint.json +++ b/pint.json @@ -47,6 +47,9 @@ }, "trim_array_spaces": true, "single_trait_insert_per_statement": false, - "new_with_parentheses": false + "new_with_parentheses": false, + "php_unit_method_casing": { + "case": "camel_case" + } } } diff --git a/src/Platform/Http/Controllers/RelationController.php b/src/Platform/Http/Controllers/RelationController.php index f2488c02d..a69778bfc 100644 --- a/src/Platform/Http/Controllers/RelationController.php +++ b/src/Platform/Http/Controllers/RelationController.php @@ -4,6 +4,8 @@ namespace Orchid\Platform\Http\Controllers; +use Composer\InstalledVersions; +use Composer\Semver\VersionParser; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Http\JsonResponse; @@ -80,14 +82,34 @@ private function buildersItems( }); } - $model = $model->where(function ($query) use ($name, $search, $searchColumns) { - $query->where($name, 'like', '%'.$search.'%'); - if ($searchColumns !== null) { - foreach ($searchColumns as $column) { - $query->orWhere($column, 'like', '%'.$search.'%'); - } - } - }); + if (InstalledVersions::satisfies(new VersionParser, 'laravel/framework', '>11.17.0')) { + $model = $model->where(function ($query) use ($name, $search, $searchColumns) { + $value = '%'.$search.'%'; + + $query->whereLike($name, $value); + + $query->when($searchColumns !== null, function ($query) use ($searchColumns, $value) { + foreach ($searchColumns as $column) { + $query->orWhereLike($column, $value); + } + }); + }); + } else { + /** + * @deprecated logic for older Laravel versions + */ + $model = $model->where(function ($query) use ($name, $search, $searchColumns) { + $value = '%'.$search.'%'; + + $query->where($name, 'like', $value); + + $query->when($searchColumns !== null, function ($query) use ($searchColumns, $value) { + foreach ($searchColumns as $column) { + $query->orWhere($column, 'like', $value); + } + }); + }); + } return $model ->limit($chunk)