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)
- Str::apa will lowercase accented words HOT 1
- Schema::getColumnType expects given column name to be lowercase HOT 3
- Backward compatibility makes `lang:publish` command useless! HOT 2
- PROPOSAL: Handling default values within \Illuminate\Queue\SerializesModels HOT 1
- Jobs in default queue not working HOT 1
- decrypt error occurs when php artisan env:decrypt is executed and the key without base64 prefix is used HOT 1
- Rules with numeric keys do not validate properly HOT 10
- 'datetime' casted attribute returning current date from am empty string in the db HOT 4
- Phpoption should be a dependency in Support HOT 1
- about FormRequest bail HOT 1
- Unescaped Reserverd keyword on Postgres HOT 2
- Custom route binding for backed enums doesn't work
- Bulk Update and Creation Report HOT 1
- Query building is failing if using '->having()' method HOT 2
- Xdebug infinite loop error HOT 1
- Unexpected behaviour creating through HasOne HOT 6
- Create method returns always first record with related internal model HOT 2
- BackedEnum on Route already resolved HOT 3
- Things break if you mix the @php(...) inline directive with @php and @endphp HOT 2
- isRelation checks only if a method exists but not if a relation is returned HOT 5
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.