Back

Laravel Relation for different User types


notflip posted 5 months ago

I have a platform where I have Users that are a Shop, they can place Orders, and I have Users that are Suppliers, they can view the placed Orders.

Now I'm running into some logic issue's, for example in my User class I woud like for the Supplier to be able to do this

Auth::user()->orders

But the User that is a shop should also be able to do this

Auth::user()->orders

I illustrated a bad example on how to do this here:

class User extends Authenticatable
{
  public function orders()
  {
      return $this->hasMany(Order::class, 'created_by');
  }

  public function alsoHasOrders()
  {
      return $this->hasMany(Order::class, 'fulfilled_by');
  }

}

There should be a better way to do this right?


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us