LaravelCollective / html

HTML and Form Builders for the Laravel Framework
MIT License
3.99k stars 783 forks source link

Action PostsController@store not defined. #711

Closed mjavadtatari closed 1 year ago

mjavadtatari commented 2 years ago

Hello, According to the Docs at [laravelcollective.com](https://laravelcollective.com/docs/6.x/html#opening-a-form), we should use echo Form::open(['action' => 'Controller@method']) format.

I tried this: {!! Form::open(['action'=>'PostsController@store']) !!}

it's not working, the Error message: InvalidArgumentException: Action PostsController@store not defined.

but I tried full address and worked: {!! Form::open(['action'=>'App\Http\Controllers\PostsController@store']) !!}

I would appreciate it if you could help me.

Php Version: 8.1.5 Laravel Version: 9.14.1

fulopattila122 commented 2 years ago

This change was introduced with Laravel 8.0, see: https://laravel.com/docs/8.x/upgrade#automatic-controller-namespace-prefixing

It's highly likely unrelated to this package, this is how Laravel 8+ works

kelseygreat commented 1 year ago

@mjavadtatari , to resolve this issue, you will need to add protected $namespace = 'App\Http\Controllers'; to your RouteServiceProvider in app/Providers/RouteServiceProvider.php

Adding the above line of code will allow you access your controller and action within the action attribute of your html form without having to use the complete path to the controller.

Hope this helps.

mjavadtatari commented 1 year ago

thank you so much @kelseygreat