Skip to content

New Rule to use the whereLike clause in Laravel 11.x #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 20, 2024

Conversation

GeniJaho
Copy link
Collaborator

@GeniJaho GeniJaho commented Oct 28, 2024

Adds a new rule WhereToWhereLike (open for a better name) that will migrate all the ->where('name', 'like', '%Rector%') clauses into the new whereLike() introduced in Laravel 11.x.

  • The rule has an optional configuration for the Postgres driver, since it uses a 'case-sensitive' search by default.
  • I would love to add it to the Laravel 11 and Code Quality sets, but we'd have to make a check in the rule for the Laravel version. In any case, it could cause issues for Postgres users if the rule is enabled by default, they'd have to configure it manually... and skip the one provided by the sets, somehow.

@GeniJaho GeniJaho added the enhancement New feature or request label Nov 4, 2024
@GeniJaho GeniJaho force-pushed the feature/where-to-where-like branch from e0d8e0b to d5a9408 Compare December 20, 2024 15:33
@GeniJaho GeniJaho requested a review from peterfox December 20, 2024 15:38
Copy link
Collaborator

@peterfox peterfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff @GeniJaho !

@GeniJaho GeniJaho merged commit 0e5b9d9 into main Dec 20, 2024
5 checks passed
@GeniJaho GeniJaho deleted the feature/where-to-where-like branch December 20, 2024 16:07
@ibrunotome
Copy link

@GeniJaho Just a note for the ones who apply this rule, tests broke when applied this rule for the first where:

before rector (passing):

  $query
    ->where('name', 'ilike', DB::raw("UNACCENT('%{$filter}%')"))
    ->orWhereRelation('approaches.influencer', DB::raw('UNACCENT(searchable)'), 'ilike', DB::raw("UNACCENT('%{$filter}%')"));

after this rector rule ("ERROR: Object of class Illuminate\Database\Query\Expression could not be converted to string")

  $query
    ->whereLike('name', DB::raw("UNACCENT('%{$filter}%')"))
    ->orWhereRelation('approaches.influencer', DB::raw('UNACCENT(searchable)'), 'ilike', DB::raw("UNACCENT('%{$filter}%')"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants