Skip to content
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

Ability to bind on desired uuid column from model #106

Merged
merged 5 commits into from
Sep 30, 2021
Merged

Ability to bind on desired uuid column from model #106

merged 5 commits into from
Sep 30, 2021

Conversation

afshiney
Copy link
Contributor

@afshiney afshiney commented Sep 16, 2021

When used on model, the added trait adds the ability to route bind the model to desired uuid column,
As an example:

Route::get('users/{user}', function (User $user){
	return $user;
});

Above code would bind on default 'uuid' column name and perform under "whereUuid" scope.

Also in case model has more than one uuid column and/or any name other than 'uuid' is set for column, the added trait feeds the custom column name to responsible scope:

public function uuidColumns(): array
{
	return ['uuid', 'other_uuid_column'];
}

Route::get('users/{user:other_uuid_column}', function (User $user){
	return $user;
});

As usual custom columns should be registered within "uuidColumns" function.

@michaeldyrynda
Copy link
Owner

Any chance we can add some tests to verify the behaviour? i.e. that the binding works on the default column, a custom value, and that it correctly returns a 404 when the model cannot be found?

@afshiney
Copy link
Contributor Author

Of course, just pushed the latest commit that contains the required tests.

@michaeldyrynda
Copy link
Owner

I added a getRouteKeyName(): string method to the BindsOnUuid trait as well. If we're going to support implicit binding, we should support it on the named routes as well. Readme updated to reflect this change, too.

I also tweaked the it_fails_on_invalid_uuid_when_custom_route_key_used test as it looked like it had been copy/pasted from the test above but not updated.

@michaeldyrynda michaeldyrynda merged commit 0a886b3 into michaeldyrynda:main Sep 30, 2021
@afshiney afshiney deleted the feature/bind-on-uuid branch September 30, 2021 20:35
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.

2 participants