-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
Added translateOrFail method to translatable trait #114
Conversation
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.
I think the method should be called translationOrFail
instead of translateOrFail
, since translate
sounds like the action of translating something 🤔
tests/TranslatableTest.php
Outdated
@@ -414,6 +415,18 @@ public function it_has_methods_that_return_always_a_translation(): void | |||
static::assertEquals('xyz', $vegetable->translateOrNew()->locale); | |||
} | |||
|
|||
/** @test */ | |||
public function it_has_methods_that_throw_an_exception_if_translation_does_not_exist(): void |
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.
it_throws_an_exception_if_translation_does_not_exist
. Using it_has_methods
doesn't seems right to me 🤔 You're not testing if those methods are added to the model, you're testing that those methods works properly
I would agree on the translateOrFail method name, but the other comparable methods are called "translateOrDefault", "translateOrNew" and "translate". Is it worth keeping them consistent? I'll change the test name to something sensible. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hey, |
Thanks again! It's released now. 🎉 https://github.com/Astrotomic/laravel-translatable/releases/tag/v11.7.0 |
Hi, I thought it would be useful to have a convenience method that throws a ModelNotFoundException if a translation does not exist, mimicking the behaviour of Eloquent's findOrFail(). Thanks for the project 😄