Skip to content

Conversation

@bfiessinger
Copy link
Contributor

implements flag fallbacks for Addresses as described in #32


Currently no flag fallback support

By using the current getters like $model->getBillingAddress() the return is way too strict and in many cases we will get a null return. But there might be a primary / shipping / any other address attached to the model that could also be used by the application.

In theses cases there should be fallback.

The solution

Besides the existing methods like getPrimaryAddress, getBillingAddress, etc. I have added a simple getAddress method. This method takes 3 arguments:

  • $flag type: string - the flag to search for, e.g. billing
  • $direction type: string - ASC / DESC
  • $strict type: boolean - using strict mode, this ensures that the current methods still behave the same way.

getAddress will first check if addresses are existing on the model and if so returns the first / last address depending on the $direction param.

If no address is found to this point it will create a fallback order based on config('lecturize.addresses.flags') and returns the next best result. If no address matches any result in this order we fallback to either the first or last address with any or no flag.

Contacts do not have any methods to query by flag

While we could write a query ourselfes like:

$model->contacts()
    ->where('is_primary', 1)
    ...

it would be much more convenient to use the same methods known from the Addresses.

So contacts can be now also be queried by $model->getContact($flag, $direction, $strict)

@bfiessinger bfiessinger closed this Sep 7, 2023
@bfiessinger bfiessinger force-pushed the feat/flag-fallback-logic branch from 525fbe7 to 28dc3f6 Compare September 7, 2023 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant