Skip to content

Commit

Permalink
Added usage new laravel method for like
Browse files Browse the repository at this point in the history
Fixed pint
  • Loading branch information
tabuna committed Nov 23, 2024
1 parent 19dbc19 commit 4f733dd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
5 changes: 4 additions & 1 deletion pint.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
38 changes: 30 additions & 8 deletions src/Platform/Http/Controllers/RelationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4f733dd

Please sign in to comment.