Home > Software engineering >  Can not use controller name in laravel, must use namespace
Can not use controller name in laravel, must use namespace

Time:05-01

Blade view and PostsController

When I use {!! Forms::open(['method'=>'post', 'action'=>'PostsController@store']) !!} It errors out.

But when I use {!! Forms::open(['method'=>'post', 'action'=>'App\Http\Contollers\PostsController@store']) !! It works.

Why cant I just use Controller name instead of namespace name?

Thanks for help.

CodePudding user response:

You could use instead the route name like that

 Form::open(['route' => 'route.name'])

for example, creating a post should be something like that

Form::open(['route' => 'posts.create'])

for more info check the docs here

CodePudding user response:

In RouteServiceProvider.php uncomment protected $namespace = 'App\Http\Controllers'; this line

  • Related