Skip to content

[9.x] add dictionary to slug helper #44730

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 4 commits into from
Oct 25, 2022

Conversation

imdhemy
Copy link
Contributor

@imdhemy imdhemy commented Oct 25, 2022

The current implementation of the Str::slug() method already replaces the @ with at. The keyboard still has some other replaceable characters.

E.g 500$ bill becomes 500-dollar-bill instead of 500-bill.

Besides, some languages have different rules for the replacement of special characters.
With the current implementation, we can have something like:

أحمد-at-المدرسة

which should be:

أحمد-في-المدرسة

This PR adds a new parameter to the Str::slug() method to allow the developer to specify the replacement character for the special characters.

It does not break the current implementation, as the default value for the new parameter is ['@' => 'at'].

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
- allows custom replacements like `@` => `at`, `$` => `dollar`

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
Copy link
Contributor

@milwad-dev milwad-dev left a comment

Choose a reason for hiding this comment

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

is useful

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@taylorotwell taylorotwell merged commit 9d4a5b3 into laravel:9.x Oct 25, 2022
@driesvints
Copy link
Member

@milwad-dev please only comment when you have something to contribute to the discussion.

@shaedrich
Copy link
Contributor

Wouldn't it be better to have a more diverse method signature like this:

Str::slug('500$ bill', [ '$' => fn($value) => /* do something */]);
Str::slug('500$ bill', fn($value) => /* do something */);
Str::slug('500$ bill', [ '/$|€/' => fn($value) => /* do something */]);

RegExp would even work quite well, since it is already used in that method.

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

Successfully merging this pull request may close these issues.

None yet

5 participants