-
Notifications
You must be signed in to change notification settings - Fork 34
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
Events do not fire when Nova UI is used. #16
Comments
I'd like to help you, but i don't have Nova license 😔 |
Hi, I got the same issues when using laravel-admin which is a CMS framework similar to Nova. Although I don't have a Nova license, I want to share my experience to fix this issues in After few hours digging in .
.
.
switch (get_class($relation)) {
case Relations\BelongsToMany::class:
case Relations\MorphToMany::class:
if (isset($prepared[$name])) {
$relation->sync($prepared[$name]);
}
break;
case Relations\HasOne::class:
.
.
. The problem is So I change the logic a little bit, and it works prefectly. And I created a pull request to .
.
.
switch (true) {
case $relation instanceof Relations\BelongsToMany:
case $relation instanceof Relations\MorphToMany:
if (isset($prepared[$name])) {
$relation->sync($prepared[$name]);
}
break;
case $relation instanceof Relations\HasOne:
.
.
. At this moment, I don't have any idea without changing the source code of |
Thanks for share @hallelujahbaby! |
I see Nova using a Illuminate\Database\Eloquent\Relations\Pivot instance to do the pivot rescue. I guess that's why events don't get launched. However, the events at the pivot update don't work that way either: Location::find(20993)->products()->first()->save(); Why is the event |
If it helps, this is what the Nova controller does when attaching a model into a morphedByMany relationship. ($pivot = $relationship->newPivot())->forceFill([
$relationship->getForeignPivotKeyName() => $request->resourceId,
$relationship->getRelatedPivotKeyName() => $request->input($request->relatedResource),
$relationship->getMorphType() => $request->findModelOrFail()->{$request->viaRelationship}()->getMorphClass(),
]); |
Any news here? |
As i can see from comments above Nova works with pivot models and doesn't support normal relations, so many-to-many relations can't be supported by this package. Ofcourse we can change basic behavior of laravel's relations, but i don't want to miss miss compatibility. |
How would you do that? |
Maybe we can implement an adaptor or a Nova component for doing that without messing with this repo? But I have no much clue of how to do it... |
@fede91it I guess, it is possible to override laravel's methods like attach, detach, etc to use pivot models. |
@chelout I might be able to provide you a license. If you're interested, could you reach me on Telegram? I'm using the same username as in here. Or email (my full name @ gmail.com). |
If necessary, I can sponsor the development of this additional feature. |
@fede91it Actually i tend not to change default logic of laravel's relation system, i tend to making Nova plug-in to support our package. If you would like to sponsor this package you can always reach me on telegram @slaffka_moscow |
Why we can't create a trait for the pivot models? |
Any updates on this? |
Came here because I was looking for the same functionality. Currently working on my Nova admin and this would solve a big issue. |
There are no updates on this topic. Sorry, guys. |
I did a proof of concept using Laravel native Pivot models events and works fine with Nova: https://github.com/arall/laravel-relationhip-events |
@arall yes, you right, it's possible with pivot events, but this package doesn't use them. |
bump? |
This is my workaround for this issue. hope it helps. First, you should create a model for pivot table.
Then, it's time to define this model to your morph relations
now you can create an observer for your Taggable model and it works perfectly fine with nova admin panel |
This package is great, does everything we need, except in Laravel Nova. When I use the Attach or Detach buttons on the Nova UI for any of my belongsToMany relationships, nothing fires, no events.
The same relationships with no code changes work great outside of Nova, and I get my events in my observer class for. In jobs running on the schedule, and even down in tinker on the command line. The events fire.
public function belongsToManyAttached($relation, Website $website, $ids)
and
public function belongsToManyDetached($relation, Website $website, $ids)
Website is the class I am observing.
The text was updated successfully, but these errors were encountered: