0

Hi i hope you can help me with this. I couldn't find an explanation in the documentation but I had this problem:

if I put the controller like this I got an error telling me the method was not defined

<a href={{ action('MovieController@create')  }}>Create Movie</a></h3>

so I get to solve it like this, puting the complete namespace

<a href={{ action('App\Http\Controllers\MovieController@create')  }}>Create Movie</a></h3>

My question is; is there any way I don't have to put the complete namespace to get it to work?

1 Answers1

0

If you want a namespace prefixed to the Controller when generating URLs to "actions" you will need to define this in your RouteServiceProvider:

protected $namespace = 'App\Http\Controllers';

Also if you do not want the prefix assigned to your Controllers for your routes by default you will have to make sure the route groups do not have this $namespace variable used to assign a namespace with the namespace method in that Service Provider.

Reference for namespace prefixing in Laravel 8: Target class controller does not exist - Laravel 8

lagbox
  • 48,571
  • 8
  • 72
  • 83