Laravel-modules: creating links to modules

Created on 24 Mar 2017  Â·  10Comments  Â·  Source: nWidart/laravel-modules

Hi there - just wondering, how do I go about creating links to modules? I am using:

{{ action('AtozController@index') }}

But I am getting:

ErrorException in UrlGenerator.php line 337:
Action App\Http\Controllers\AtozController@index not defined. (View: /home/vagrant/Code/App/resources/views/home.blade.php)

Most helpful comment

You probably need to use the fully qualified namespace for your module's controller:

{{ action('\Modules\MyModule\Http\Controllers\AtozController@index') }}

I highly suggest named routes instead. I've never understood why one would use action (or raw uris) when naming your routes is so much more backwards compatible.

All 10 comments

Same problem, I tried with action('Home::HomeController@index'), but now working.

I think the best form for do it, its probably adding a method to module class and fecade, and get route of the action doing it:

$module = Module::find('home');
$module->action('ControllerInModule@method');

And obviusly, in a single line:
Module::find('Home')->action('ControllerInModule@method')

Or maybe directly with Fecade:

Module::action('Home', 'ControllerInModule@method')

@nWidart This weekend I'll study about how it's made the package and probably send a pull request with this feature.

You probably need to use the fully qualified namespace for your module's controller:

{{ action('\Modules\MyModule\Http\Controllers\AtozController@index') }}

I highly suggest named routes instead. I've never understood why one would use action (or raw uris) when naming your routes is so much more backwards compatible.

I was using action because I did not know the named routes.

Thanks for link in documentation, I'll use named routes now.

I am using action as I have resource controllers

On Fri, 24 Mar 2017 at 18:30, montyclt notifications@github.com wrote:

I was using action because I did not know the named routes.

Thanks for link in documentation, I'll use named routes now.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/nWidart/laravel-modules/issues/178#issuecomment-289107845,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAmgpMh_gpQkr675yM4qpCTXBlj2g6cuks5rpAu0gaJpZM4MoCOh
.

Resource controllers (depending on the version of Laravel) create named routes (or you can manually create them). https://laravel.com/docs/5.4/controllers#resource-controllers

You can always check the route list if you're not sure:

php artistan route:list

By "manually create", I mean Route::resource() has the option to name routes, just like you can exclude or only include certain resources.

Well stone the crow! I never realised that!

Amazing what you miss! Thanks!!!

On Fri, 24 Mar 2017 at 18:42, Micheal Mand notifications@github.com wrote:

Resource controllers (depending on the version of Laravel) create named
routes (or you can manually create them).
https://laravel.com/docs/5.4/controllers#resource-controllers

You can always check the route list if you're not sure:

php artistan route:list

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/nWidart/laravel-modules/issues/178#issuecomment-289110862,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAmgpKuveqqSWtZPZa1iqSh6kWPurjj1ks5rpA6CgaJpZM4MoCOh
.

No problem. :)

I'll close this as it looks fixed 😄

Was this page helpful?
0 / 5 - 0 ratings

Related issues

elephantux picture elephantux  Â·  11Comments

FoksVHox picture FoksVHox  Â·  11Comments

KyawNaingTun picture KyawNaingTun  Â·  16Comments

jakecorn picture jakecorn  Â·  16Comments

echemik picture echemik  Â·  10Comments