0

We have an API which connects to our own first party applications. Our API is sending out notifications based on user actions or if there is an update to the application etc.

Our API is modular structured.

Example

Our user model in API is located in App\Modules\Accounts\Models\User. Each month we send an invoice database notification to user from our API. In database it adds the notification and the notifiable_type is App\Modules\Accounts\Models\User.

enter image description here

But in our user application the user model is located in App\Modules\User which results user having 0 notifications.

Question

I know I can move the user model to exactly the same path in the user application but it seems somewhat wrong. Is there a way to tell the user model in our user application where to receive database notification on? Something like:

public function(){
    return $this->receivesNotificationsFrom('App\Modules\Accounts\Models\User');
}
z0mbieKale
  • 969
  • 1
  • 14
  • 44

1 Answers1

0

I would solve this in api as like this (suggesting, i would also use your namespace for users like you did, what i would never do, but lets suggest it). There are several ways to test, what is the best solution for you.

I would:

  1. In your consuming app, you create a new model App\Modules\Accounts\Models\User that just extends your existing User class. I would test, if i can get to goal with this approach.

  2. You create an artisan command to just rename the classes in your notification table and let this run by laravel's scheduler, so in your notifications table are the correct namespaces for your app.

  3. This all "feels" wrong and i would never break with the defaults of App\User, because you run into traps like this and end up with "messy" solutions like 1 or 2.

Sry, i have no better ideas now, but maybe, it gives you some little inspirations

Paladin
  • 1,637
  • 13
  • 28