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

Added translateOrFail method to translatable trait #114

Merged
merged 2 commits into from
Jan 28, 2020

Conversation

rb1193
Copy link
Contributor

@rb1193 rb1193 commented Dec 24, 2019

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 😄

Copy link
Contributor

@Lloople Lloople left a 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 🤔

@@ -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
Copy link
Contributor

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

@rb1193
Copy link
Contributor Author

rb1193 commented Dec 27, 2019

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.

@Astrotomic Astrotomic deleted a comment from rb1193 Dec 27, 2019
@stale
Copy link

stale bot commented Jan 10, 2020

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.

@stale stale bot added the stale label Jan 10, 2020
@Gummibeer Gummibeer removed the stale label Jan 11, 2020
@stale
Copy link

stale bot commented Jan 24, 2020

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.

@stale stale bot added the stale label Jan 24, 2020
@stale stale bot removed the stale label Jan 24, 2020
@Gummibeer
Copy link
Member

Hey,
I'm super sorry for the massive delay! 😔
Primary because this is an awesome and complete PR! 💙🚀
@rb1193 I will possibly merge it this night, otherwise on Sunday or latest on Monday.

@Gummibeer Gummibeer merged commit 5203dbf into Astrotomic:master Jan 28, 2020
@Gummibeer
Copy link
Member

Thanks again! It's released now. 🎉

https://github.com/Astrotomic/laravel-translatable/releases/tag/v11.7.0

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

Successfully merging this pull request may close these issues.

3 participants