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

[9.x] Define a new method to create a through model #41444

Merged
merged 1 commit into from Mar 14, 2022
Merged

[9.x] Define a new method to create a through model #41444

merged 1 commit into from Mar 14, 2022

Conversation

hafezdivandari
Copy link
Contributor

It is helpful to have a customizable method for creating a new model instance for a through model without overriding the whole hasOneThrough or hasManyThrough methods. It is just as useful as newRelatedInstance method.

@taylorotwell
Copy link
Member

Can you describe your use case for this?

@hafezdivandari
Copy link
Contributor Author

hafezdivandari commented Mar 13, 2022

@taylorotwell sure, I wanted to pass the table name instead of the class and set the through model's table dynamically, something like this:

protected function newRelatedThroughInstance($resource)
{
    return (new \App\Models\Entity)->setTable($resource);
}

As I said in the comment above, the use case can be setting the model's connection or table conditionally/dynamically just like newRelatedInstance method.

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.

None yet

2 participants