ingeniasoftware / luthier-ci

Improved routing, middleware support, authentication tools and more for CodeIgniter 3 framework
https://luthier.ingenia.me/ci/en/
MIT License
151 stars 39 forks source link

can't resolve namespace inside route group #13

Closed ericksuryadinata closed 6 years ago

ericksuryadinata commented 6 years ago

I have

Route::group('admin',['namespace' => 'admin'], function(){
    Route::group('gate',['namespace' => 'Auth'], function(){
        Route::get('in','AuthController@index')->name('admin.auth.index');
    })
});

but it give me 404, any mistake in my code?? usually i'm using this in laravel

andersonsalas commented 6 years ago

Where is located your controller file? That route is mapped by Luthier-CI as follow:

  "admin/gate/in" => [
    "GET" => "admin/Auth/AuthController/index"
  ]

So, your controller file must be placed in application/controllers/admin/Auth/AuthController.php

CodeIgniter controllers doesn't have actual namespaces, so that route property will be traited as an directory path.

ericksuryadinata commented 6 years ago

I solved that, but now i have this

I realize that

Route::group('admin',['namespace' => 'admin'], function(){
    Route::group('/',['middleware' => ['AdminMiddleware']], function(){
        Route::group('profile',['namespace' => 'Profile'],function(){
            Route::get('facility','ProfileController@index')->name('admin.profile.facility');
        });
    });
});

give me url localhost/admin//profile/ instead of localhost/admin/profile there's double / in url

so i did

Route::group('admin',['namespace' => 'admin'], function(){
    Route::group('/',['middleware' => ['AdminMiddleware']], function(){
        Route::group('/',['namespace' => 'Profile'],function(){
            Route::get('facility','ProfileController@index',['prefix' => 'profile'])->name('admin.profile.facility');
        });
    });
});

this give me correct link,

any suggest, i want to write like the first function thanks,

andersonsalas commented 6 years ago

Yes, that's a bug :disappointed: . Thanks for report it.

I've founded the reason:

https://github.com/ingeniasoftware/luthier-ci/blob/5e706187a3029512c948bc36f2c816bf9a1ef2ed/src/Route.php#L212

A workaround, as you suggested, is this alternate syntax:

Route::group('admin',['namespace' => 'admin'], function(){
    Route::group('/',['middleware' => ['AdminMiddleware']], function(){
        Route::group('/',['namespace' => 'Profile'],function(){
            Route::get('facility','ProfileController@index',['prefix' => 'profile'])->name('admin.profile.facility');
        });
    });
});

It will be fixed in the 0.3.0 release in a few days.

ericksuryadinata commented 6 years ago

uhmm, thanks for the explanation and for the good work :smile: maybe i'll use that, and waiting for the update..