Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model extending #1661

Open
wants to merge 113 commits into
base: 1.x
Choose a base branch
from
Open

Model extending #1661

wants to merge 113 commits into from

Conversation

alecritson
Copy link
Collaborator

This PR looks to build on the current work done for model extending and includes but not limited to the following changes:

  • Filament resources use the model contract for DI
  • Change to use Laravel's morphMap instead of having concrete classes in the database for polymorphic relationships
  • There was an issue with custom models when they extended Lunar ones, the newFactory method didn't like having the return type.
  • Added a addDir
  • Tweaked guessContractClass to take namespace into account as not all Lunar models (from addons) will have the same namespace
  • Added addDirectory method to prevent excessive calls to replace or add methods.
  • Updated relationships to use modelClass()
  • Static functions should forward to the custom class when called.
  • If a custom class name is different to the one it extends i.e. App\Models\MyProduct instead of App\Models\Product it will still use the correct table name.
  • Tweaked observe method on models that use HasModelExtending to forward to the custom class even if observe is called on the Lunar model.
  • Removed redundant tests and updated docs.

Set as draft for the moment as there is a fair amount of changes so just want to double check before hitting the button.

glennjacobs and others added 30 commits December 21, 2023 14:39
Co-authored-by: wychoong <67364036+wychoong@users.noreply.github.com>
# Conflicts:
#	packages/core/src/Models/Currency.php
@AidasK
Copy link

AidasK commented Apr 14, 2024

InstallLunar class should be also updated right? It currently uses 'attributable_type' => Product::class, and instead it should pick the morphed name.

@alecritson alecritson changed the base branch from feature/model-extending to 1.x April 17, 2024 14:33
@glennjacobs glennjacobs changed the title Feat - Expand on model extending Model extending Apr 19, 2024
@@ -175,6 +175,8 @@ public function register(): void
$this->app->singleton(DiscountManagerInterface::class, function ($app) {
return $app->make(DiscountManager::class);
});

\Lunar\Facades\ModelManifest::register(); // Facade is the same name as the class, change??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we need to address the comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the comment, not sure what needs changing as it's a common pattern in Laravel?

packages/core/src/Models/Address.php Outdated Show resolved Hide resolved
docs/core/extending/models.md Outdated Show resolved Hide resolved
docs/core/extending/models.md Outdated Show resolved Hide resolved
docs/core/extending/models.md Show resolved Hide resolved
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.

None yet

5 participants