-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
Add Cuid2 Support #54375
Draft
xaoseric
wants to merge
20
commits into
laravel:11.x
Choose a base branch
from
xaoseric:add-cuid-support
base: 11.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+396
−3
Draft
Add Cuid2 Support #54375
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4e8cbc0
Add cuid2 support
xaoseric d732778
fix style issues.
xaoseric 21f09c6
fix blueprint style issues
xaoseric cf0c69b
fix stylci errors
xaoseric cb49609
fix format in str class
xaoseric ad5a262
fix styleci spacing issue
xaoseric d1d05af
fix line issue
xaoseric c708ddc
add space back to fix styleci.
xaoseric c96fbb5
make styleci happy with LF formatting.
xaoseric c0aa78c
add LF space back for styleci formatting
xaoseric 9e43f41
make if statement readable
xaoseric 71d9b2f
fix styleci issues
xaoseric 3cca8d0
fix spacing in if statement
xaoseric 73a98e4
add tests for Cuid validation
xaoseric 0a2423d
Merge branch 'laravel:11.x' into add-cuid-support
xaoseric d1e6c9a
add tests for Cuid database fields
xaoseric e8d9b27
modify blueprint to use char instead
xaoseric 1b41167
fix cuid classes to use HasCuid
xaoseric f49f414
fix EloquentModelUsingCuid to import HasCuid
xaoseric 53229ac
fix import order and styleci issues.
xaoseric File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
return [ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Cuid Options | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This will allow you to control the length of your cuid id generation, 24 by default | ||
| | ||
*/ | ||
'length' => env('CUID_LENGTH', 24), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Illuminate\Database\Eloquent\Concerns; | ||
|
||
use Illuminate\Support\Str; | ||
use Visus\Cuid2\Cuid2; | ||
|
||
trait HasCuid | ||
{ | ||
use HasUniqueStringIds; | ||
|
||
/** | ||
* Generate a new unique key for the model. | ||
*/ | ||
public function newUniqueId(): string | ||
{ | ||
$size = intval(config('cuid.length', 24)); | ||
$cuid = new Cuid2(maxLength: ($size < 2 || $size > 32) ? 24 : $size); | ||
|
||
return $cuid->toString(); | ||
} | ||
|
||
/** | ||
* Determine if given key is valid. | ||
* | ||
* @param mixed $value | ||
*/ | ||
protected function isValidUniqueId($value): bool | ||
{ | ||
return Str::isCuid($value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This maintainer isn't very active. I'd be very hesitant to base the framework on this package's support.