laravel-enso / enso

Laravel Vue SPA, Bulma themed. For demo login use `admin@laravel-enso.com` & `password` -
https://www.laravel-enso.com
MIT License
1.08k stars 277 forks source link

4.2 - Invalid route action: [Reports\Packages\Invoiceannexes\Index] after creating a new crud structure with enso:cli #342

Closed pongraczi closed 3 years ago

pongraczi commented 3 years ago

This is a possible bug.

Prerequisites

Description

laravel@ensodev:/var/www/laravel$ php artisan migrate

   UnexpectedValueException 

  Invalid route action: [Reports\Packages\Invoiceannexes\Index].

  at vendor/laravel/framework/src/Illuminate/Routing/RouteAction.php:91
     87▕      */
     88▕     protected static function makeInvokable($action)
     89▕     {
     90▕         if (! method_exists($action, '__invoke')) {
  ➜  91▕             throw new UnexpectedValueException("Invalid route action: [{$action}].");
     92▕         }
     93▕ 
     94▕         return $action.'@__invoke';
     95▕     }

  • `Reports\Packages\Invoiceannexes\Index` was not found: Controller class `Reports\Packages\Invoiceannexes\Index` for one of your routes was not found. Are you sure this controller exists and is imported correctly? 

      +8 vendor frames 
  9   routes/api.php:43
      Illuminate\Support\Facades\Facade::__callStatic()

      +3 vendor frames 
  13  routes/api.php:52
      Illuminate\Routing\RouteRegistrar::group()

I expected the process could complete without error, even customizing the generated files.
Or did I miss something?

Steps to Reproduce

Complete process log to follow the creation of a new crud structure using enso:cli ```bash laravel@ensodev:/var/www/laravel$ php artisan enso:cli Create a new Laravel Enso Structure Current configuration status: Model ✗ Permission Group ✗ Permissions ✗ Menu ✗ Files ✗ Package ✗ Choose element to configure: [0] Model [1] Permission Group [2] Permissions [3] Menu [4] Files [5] Package [6] Generate [7] Toggle Validation [8] Exit > 0 Model configuration: name => Configure Model (yes/no) [no]: > App/Reports/Packages/Invoiceannexes Current configuration status: Model ✗ Permission Group ✗ Permissions ✗ Menu ✗ Files ✗ Package ✗ Choose element to configure: [0] Model [1] Permission Group [2] Permissions [3] Menu [4] Files [5] Package [6] Generate [7] Toggle Validation [8] Exit > 0 Model configuration: name => Configure Model (yes/no) [no]: > y name: > App/Reports/Packages/Invoiceannexes Current configuration status: Model ✓ Permission Group ✗ Permissions ✗ Menu ✗ Files ✗ Package ✗ Choose element to configure: [0] Model [1] Permission Group [2] Permissions [3] Menu [4] Files [5] Package [6] Generate [7] Toggle Validation [8] Exit > 1 Permission Group configuration: name => Configure Permission Group (yes/no) [no]: > y name: > reports.packages.invoiceannexes Current configuration status: Model ✓ Permission Group ✓ Permissions ✗ Menu ✗ Files ✗ Package ✗ Choose element to configure: [0] Model [1] Permission Group [2] Permissions [3] Menu [4] Files [5] Package [6] Generate [7] Toggle Validation [8] Exit > 2 Permissions configuration: index => ✗ create => ✗ store => ✗ show => ✗ edit => ✗ update => ✗ destroy => ✗ initTable => ✗ tableData => ✗ exportExcel => ✗ options => ✗ Configure Permissions (yes/no) [no]: > y index (yes/no) [no]: > y create (yes/no) [no]: > store (yes/no) [no]: > show (yes/no) [no]: > y edit (yes/no) [no]: > update (yes/no) [no]: > destroy (yes/no) [no]: > initTable (yes/no) [no]: > y tableData (yes/no) [no]: > y exportExcel (yes/no) [no]: > y options (yes/no) [no]: > y Current configuration status: Model ✓ Permission Group ✓ Permissions ✓ Menu ✗ Files ✗ Package ✗ Choose element to configure: [0] Model [1] Permission Group [2] Permissions [3] Menu [4] Files [5] Package [6] Generate [7] Toggle Validation [8] Exit > 3 Menu configuration: name => icon => parentMenu => route => order_index => 999 has_children => ✗ Configure Menu (yes/no) [no]: > y name: > Invoiceannexes icon: > car parentMenu: > Reports.Packages route: > index order_index: > 100 has_children (yes/no) [no]: > Current configuration status: Model ✓ Permission Group ✓ Permissions ✓ Menu ✓ Files ✗ Package ✗ Choose element to configure: [0] Model [1] Permission Group [2] Permissions [3] Menu [4] Files [5] Package [6] Generate [7] Toggle Validation [8] Exit > 4 Files configuration: model => ✗ structure => ✗ routes => ✗ views => ✗ form => ✗ table => ✗ options => ✗ Configure Files (yes/no) [no]: > y model (yes/no) [no]: > y structure (yes/no) [no]: > y routes (yes/no) [no]: > y views (yes/no) [no]: > y form (yes/no) [no]: > y table (yes/no) [no]: > y options (yes/no) [no]: > y Current configuration status: Model ✓ Permission Group ✓ Permissions ✓ Menu ✓ Files ✓ Package ✗ Will generate: model structure routes views form table options Choose element to configure: [0] Model [1] Permission Group [2] Permissions [3] Menu [4] Files [5] Package [6] Generate [7] Toggle Validation [8] Exit > 6 Copy and paste the following code into your api.php routes file: group(function () { Route::namespace('Reports\Packages\Invoiceannexes') ->prefix('reports/packages/invoiceannexes') ->as('reports.packages.invoiceannexes.') ->group(function () { Route::get('', 'Index')->name('index'); Route::get('initTable', 'InitTable')->name('initTable'); Route::get('tableData', 'TableData')->name('tableData'); Route::get('exportExcel', 'ExportExcel')->name('exportExcel'); Route::get('options', 'Options')->name('options'); Route::get('{invoiceannexes}', 'Show')->name('show'); }); }); laravel@ensodev:/var/www/laravel/routes$ cat api.php namespace('Dashboard') ->prefix('dashboard')->as('dashboard.') ->group(function () { Route::get('line', [ChartController::class, 'line']) ->name('line'); Route::get('bar', [ChartController::class, 'bar']) ->name('bar'); Route::get('pie', [ChartController::class, 'pie']) ->name('pie'); Route::get('doughnut', [ChartController::class, 'doughnut']) ->name('doughnut'); Route::get('radar', [ChartController::class, 'radar']) ->name('radar'); Route::get('polar', [ChartController::class, 'polar']) ->name('polar'); Route::get('bubble', [ChartController::class, 'bubble']) ->name('bubble'); }); Route::middleware(['auth', 'core']) ->group(function () { // add your local routes }); Broadcast::routes(['middleware' => ['auth:sanctum']]); Route::middleware(['api', 'auth', 'core']) ->group(function () { Route::namespace('Reports\Packages\Invoiceannexes') ->prefix('reports/packages/invoiceannexes') ->as('reports.packages.invoiceannexes.') ->group(function () { Route::get('', 'Index')->name('index'); Route::get('initTable', 'InitTable')->name('initTable'); Route::get('tableData', 'TableData')->name('tableData'); Route::get('exportExcel', 'ExportExcel')->name('exportExcel'); Route::get('options', 'Options')->name('options'); Route::get('{invoiceannexes}', 'Show')->name('show'); }); }); laravel@ensodev:/var/www/laravel$ php artisan migrate UnexpectedValueException Invalid route action: [Reports\Packages\Invoiceannexes\Index]. at vendor/laravel/framework/src/Illuminate/Routing/RouteAction.php:91 87▕ */ 88▕ protected static function makeInvokable($action) 89▕ { 90▕ if (! method_exists($action, '__invoke')) { ➜ 91▕ throw new UnexpectedValueException("Invalid route action: [{$action}]."); 92▕ } 93▕ 94▕ return $action.'@__invoke'; 95▕ } • `Reports\Packages\Invoiceannexes\Index` was not found: Controller class `Reports\Packages\Invoiceannexes\Index` for one of your routes was not found. Are you sure this controller exists and is imported correctly? +8 vendor frames 9 routes/api.php:43 Illuminate\Support\Facades\Facade::__callStatic() +3 vendor frames 13 routes/api.php:52 Illuminate\Routing\RouteRegistrar::group() ```
pongraczi commented 3 years ago

Just for the record, the correct route namespace should be full path, like this:
App\Http\Controllers\Reports\Packages\Invoiceannexes

So, the file routes/api.phpshould contains the following:

Route::middleware(['api', 'auth', 'core'])
    ->group(function () {
-        Route::namespace('Reports\Packages\Invoiceannexes')
+        Route::namespace('App\Http\Controllers\Reports\Packages\Invoiceannexes')
            ->prefix('reports/packages/invoiceannexes')
            ->as('reports.packages.invoiceannexes.')
            ->group(function () {

                Route::get('', 'Index')->name('index');
                Route::get('create', 'Create')->name('create');
                Route::post('', 'Store')->name('store');
                Route::get('{invoiceAnnexes}/edit', 'Edit')->name('edit');

                Route::patch('{invoiceAnnexes}', 'Update')->name('update');

                Route::delete('{invoiceAnnexes}', 'Destroy')->name('destroy');

                Route::get('initTable', 'InitTable')->name('initTable');
                Route::get('tableData', 'TableData')->name('tableData');
                Route::get('exportExcel', 'ExportExcel')->name('exportExcel');

                Route::get('options', 'Options')->name('options');
                Route::get('{invoiceAnnexes}', 'Show')->name('show');
        });
    });

In this case the error message is gone, but other problems appear:

As I can see, the show, edit, delete buttons does not use the route prefix, because when I click on the show button, the url of the browser jumps to / instead of /reports.packages.invoiceannexes

It seems the enso:cli is not really up to date.

pongraczi commented 3 years ago

Clicking on the edit button, the browser url shows: http://domain.tld/ while the screen does not change and in the console I got this error message:

Error: Route Error: "invoiceAnnexes" key is required for route "reports.packages.invoiceannexes.edit"
    at i.throwMissingKeyError (chunk-vendors.ef3142e0.js:53)
    at i.optionalParam (chunk-vendors.ef3142e0.js:53)
    at i.fillParam (chunk-vendors.ef3142e0.js:53)
    at chunk-vendors.ef3142e0.js:53
    at String.replace (<anonymous>)
    at i.fillParams (chunk-vendors.ef3142e0.js:53)
    at i.buildUrl (chunk-vendors.ef3142e0.js:53)
    at i.get (chunk-vendors.ef3142e0.js:53)
    at a.route (chunk-vendors.ef3142e0.js:1)
    at a.default (chunk-5add0ec2.1d7ead9f.js:1)

After this I can click on the menu etc., nothing happens, I have to reload the page to get it work.

aocneanu commented 3 years ago

@pongraczi since the L8 upgrade we are no longer using the namespace helper in our routes, we use MyController::class and import the controller namespace. example

pongraczi commented 3 years ago

Ok, in this case the enso:cli and documentation should contain a warning, because all these issues appeared when I followed the documentation about how to create a CRUD

Thanks, now it is clear.

aocneanu commented 3 years ago

You are right, we will update it asap.