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

Adds Validation Rule format for use with Orbit #38

Merged
merged 3 commits into from
Mar 24, 2021

Conversation

erickpatrick
Copy link
Contributor

Background
After adding this package to an existing Laravel project by following the description in the Readme file, I started to test out the Laravel project functionality and ended up seeing errors when trying to save Models.

After some investigation, I found out that the custom Form Requests I have created to validate my form submissions were using rules that require verification of existence or uniqueness of an entry into a database table. That was done using the builtin Laravel Validation Rules exists and unique.

Solution
Realising that this package heavily relies in the Model itself to act, I've decided to change the rule format to the alternative Eloquent (Model) format, which uses the Eloquent fully qualified name (FQN) instead of the database table name. Doing so, we force Laravel to directly use the Model which uses Orbit behind the scenes instead of going to the database and search for the table name and make the checks.

With this change, this specific behaviour is now visible for others that may face the same situation.

Notes
Please, feel free to amend the text I've added to the Readme and test the solution yourself before accepting this PR.

erickpatrick and others added 2 commits March 24, 2021 21:54
*Background*
After adding this package to an existing Laravel project by following the description in the Readme file, I started to test out the Laravel project functionality and ended up seeing errors when trying to save Models.

After some investigation, I found out that the custom Form Requests I have created to validate my form submissions were using rules that require verification of existence or uniqueness of an entry into a database table. That was done using the builtin Laravel Validation Rules `exists` and `unique`.

*Solution*
Realising that this package heavily relies in the Model itself to act, I've decided to change the rule format to the alternative Eloquent (Model) format, which uses the Eloquent fully qualified name (FQN) instead of the database table name. Doing so, we force Laravel to directly use the Model which uses Orbit behind the scenes instead of going to the database and search for the table name and make the checks.

With this change, this specific behaviour is now visible for others that may face the same situation.

*Notes*
Please, feel free to amend the text I've added to the Readme and test the solution yourself before accepting this PR.
@ryangjchandler
Copy link
Owner

Thanks @erickpatrick - I've generalised the README a bit since this applies to anywhere that uses validation rules, not just Form Requests.

@ryangjchandler ryangjchandler merged commit 9ce4273 into ryangjchandler:main Mar 24, 2021
@erickpatrick
Copy link
Contributor Author

Thanks @ryangjchandler! Makes total sense the adjustment. And as you said yourself, since this works anywhere a Validation Rule would work, it also works when working with Livewire =)

@erickpatrick erickpatrick deleted the patch-1 branch March 24, 2021 21:12
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