Update Scout index on cascade deleted models

Posted 1 year ago by lmartins

I have a situation where I have two models: User and Purchase. The Purchase model is indexed via Scout and pushed to Algolia.

The purchase is setup so that when a user is deleted, the associated purchases are also removed from the BD:

        Schema::create('purchases', function (Blueprint $table) {
            $table->uuid('id');
            $table->primary('id');
            $table->integer('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->tinyInteger('status')->default(0);
            $table->timestamps();
        });

Problem is when the user is deleted even though the purchase is removed from the DB, it stays indexed in Algolia. Am I missing any step?

Thanks!

Please sign in or create an account to participate in this conversation.