Skip to content

Conversation

malayvuong
Copy link

Description

This PR fixes the incorrect model namespace generated in observers.

Previously, running:

php artisan module:make-observer MenuItem Core

would generate:

<?php

namespace Modules\Core\Observers;

use Modules\Core\app\Models\MenuItem; // ❌ wrong (includes "app")
use App\Observers\AbstractObserver;

final class MenuItemObserver extends AbstractObserver
{
    protected function modelClass(): string
    {
        return MenuItem::class;
    }
}

Root Cause

The command was converting the generator path (app/Models) directly into a namespace, which caused the app/ segment to leak into the namespace (Modules\Core\app\Models).

Fix

  • Strip the configured app_folder prefix (app/) from the generator path before building the namespace.
  • After this change, the generated observer correctly imports the model as:
use Modules\Core\Models\MenuItem; // ✅ correct

Impact

  • Works with the default app/ folder.
  • Also works if app_folder is customized (e.g. src/) in the module config.
  • No breaking changes, only affects namespace resolution in generated classes.

Fixed from `use Modules\Core\app\Models\MenuItem;` to `use Modules\Core\Models\MenuItem;` make sure namespace correct.
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