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..a3db33406 100644 --- a/src/Platform/Http/Controllers/RelationController.php +++ b/src/Platform/Http/Controllers/RelationController.php @@ -10,6 +10,8 @@ use Illuminate\Support\Collection as BaseCollection; use Illuminate\Support\Facades\Crypt; use Orchid\Platform\Http\Requests\RelationRequest; +use Composer\InstalledVersions; +use Composer\Semver\VersionParser; class RelationController extends Controller { @@ -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)