Comments (8)
Thank you for reporting this issue!
As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.
If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.
Thank you!
from framework.
Could you maybe try the solution from this issue? #48277
from framework.
Hey @driesvints I started work on a possible fix but unsure if it's the right way to go forward.
I left it as a draft for now as the ->attach()
works as expected but the get functionality is still broken. :(
from framework.
Thanks @edwwaarrdd. To be very honest, often when Pivot models are stretched like this we recommend to just use a dedicated eloquent model. I'm not sure if we should do any major changes.
from framework.
@shortontech @edwwaarrdd This is a very fundamental issue that can't be solved (without dirty hacks):
Calling $this->belongsToMany(Category::class)
already creates the relationship's base query and so applying ->using()
afterwards doesn't change the pivot table anymore.
There is an undocumented behavior, in that you can pass a Pivot instance to the $table parameter, which does not run into this issue, but the name of the variable gives no hint at this behavior (and is undocumented).
I agree that the solution should be documented, as this topic comes up regularly.
from framework.
@staudenmeir Yes I agree with this. Started tinkering a little bit but it became clear pretty fast that it's not something easy to fix.
So @shortontech if you want to fix your issue instead of declaring your belongs to many like this:
public function categories()
{
return $this->belongsToMany(Category::class)->using(CardCategory::class);
}
You can write it this way:
public function categories()
{
return $this->belongsToMany(Category::class, CardCategory::class);
}
And it will work the same as ->using()
but the $table variable will be respected as it calls the using() function in the construct of the belongsToMany class.
I am going to close my PR
Thanks for the quick responses @driesvints & @staudenmeir
from framework.
Yeah I think we should as well. Thanks @staudenmeir. Would appreciate a PR to the docs if possible!
from framework.
Added a small extra section for it in the docs.
from framework.
Related Issues (20)
- Validator Error message not being created correctly HOT 8
- The Laravel new command does not work when Herd is not installed HOT 3
- Job gets stuck in pending when dependent model is deleted inside the handle method. HOT 2
- Laravel 11.10 "artisan about" issue HOT 2
- SQLite queries generated by Eloquent with non existing columns in WHERE clause should generate an error/exception but don't HOT 1
- Laravel 10 mailer failover inline image crackd. when the first mail send fail HOT 3
- `Bus::chain` Skipping jobs with readonly non-scalar properties HOT 13
- RequiredIf validator with multiple values fails validating HOT 1
- Incorrect Sorting with UUID Data Type in MariaDB HOT 11
- orWhere ignore the first condition (where)
- Web and API non existing route files usage does not trigger an error when loaded from bootstrap/app file HOT 1
- `view()` is rendered when passed as component attribute HOT 1
- 2006 MySQL server has gone away in queue:work scenario HOT 1
- Closure in job chain is not called if preceded by job batch HOT 2
- Error with AJAX request HOT 1
- Custom cast class overrides the related column HOT 6
- Any form validation request class has strange behaviour with annotations
- sebastian/comparator should be an explicit dependency HOT 1
- current transaction is aborted, commands ignored until end of transaction block on listener when implement ShoudlQueue HOT 1
- Termwind\render(): Argument #2 ($options) must be of type int, null given
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from framework.