| 1: | <?php |
| 2: | |
| 3: | namespace LaravelUi5\Core\Contracts; |
| 4: | |
| 5: | /** |
| 6: | * Contract for models that are associated with a BusinessPartner. |
| 7: | * |
| 8: | * This interface provides a standardized way for the framework to access |
| 9: | * the `BusinessPartnerInterface` related to an authenticated user or |
| 10: | * another domain entity. |
| 11: | * |
| 12: | * Use Cases: |
| 13: | * - Resolving the acting BusinessPartner from Auth::user(). |
| 14: | * - Supporting impersonation (e.g. session-stored partner IDs). |
| 15: | * - Enforcing a consistent link between User models and BusinessPartner. |
| 16: | * |
| 17: | * Implementing Classes: |
| 18: | * - Typically applied to your User model (`App\Models\User`). |
| 19: | * - Can also be implemented by other models that carry a partner context. |
| 20: | * |
| 21: | * Example: |
| 22: | * <code> |
| 23: | * class User extends Authenticatable implements HasBusinessPartnerInterface |
| 24: | * { |
| 25: | * public function partner(): ?BusinessPartnerInterface |
| 26: | * { |
| 27: | * return $this->belongsTo(BusinessPartner::class, 'partner_id')->first(); |
| 28: | * } |
| 29: | * } |
| 30: | * </code> |
| 31: | * |
| 32: | * @see BusinessPartnerInterface |
| 33: | */ |
| 34: | interface HasBusinessPartnerInterface |
| 35: | { |
| 36: | /** |
| 37: | * Returns the BusinessPartner instance associated with this entity, |
| 38: | * or null if none is assigned. |
| 39: | * |
| 40: | * @return BusinessPartnerInterface|null |
| 41: | */ |
| 42: | public function partner(): ?BusinessPartnerInterface; |
| 43: | } |
| 44: |