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

Saving & Deleting events not working #2436

Open
kemalkanok opened this issue Aug 19, 2022 · 2 comments
Open

Saving & Deleting events not working #2436

kemalkanok opened this issue Aug 19, 2022 · 2 comments
Labels
Needs investigation Need investigation about bugs described in issue

Comments

@kemalkanok
Copy link

kemalkanok commented Aug 19, 2022

  • Laravel-mongodb Version: 3.9.0
  • PHP Version: 8.1.2
  • Database Driver & Version:
    linux mongodb 5.0.8

Description:

Hi there,
Whenever i try to use saving and deleting methods i coudn't make it work.

Code:

`

public function saving($model)
{
   dd($model);
}

public function updating($model)
{
   dd($model);
}

public function deleting($model)
{
    
      dd($model);
}

`

Steps to reproduce

1.Create an observer
2.Try using saving method
3.Try using deleting method

Expected behaviour

  1. Saving event should catch the model instance before updating
    2.Deleting event should catch the model instance before deleting

Actual behaviour

1.Saving catches the model instance after updating
2.Deleting event never catches any event.

Logs:

Log

@Smolevich Smolevich added the Needs investigation Need investigation about bugs described in issue label Sep 1, 2022
@vinslav
Copy link

vinslav commented Sep 15, 2022

I use

public function saving(Brand $brand) {
    $brand->{BrandContract::FIELD_SLUG} = Str::slug($brand->{BrandContract::FIELD_NAME});
}

Works great

@lechuhuuha
Copy link

still have error in
"jenssegers/mongodb": "3.8.4",
Laravel Framework 8.83.25
"mongodb/mongodb": "^1.12",

class TrackingLog extends Model
{
    /**
     * Bootstrap any application services.
     */
    public static function boot()
    {
        parent::boot();

        static::deleting(function ($item) {
            dd("deltee");
        });
    }

    public function clickLogs()
    {
        return $this->hasMany('EMA\Model\MongoDb\ClickLog', 'message_id', 'message_id');
    }
}

class ClickLog extends Model
{
   public static function boot()
   {
    /**
     * Associations.
     *
     * @var object | collect
     */
    public function trackingLog()
    {
        //return $this->belongsTo('EMA\Model\TrackingLog', 'message_id', 'message_id');
        return $this->belongsTo('EMA\Model\MongoDb\TrackingLog', 'message_id', 'message_id');
    }
   }
}```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs investigation Need investigation about bugs described in issue
Projects
None yet
Development

No branches or pull requests

4 participants