Reputation: 20302
I want to submit a form, but I always get Action App\Http\Controllers\About@show not defined
even though the function show
is defined:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class AboutController extends Controller
{
public function create()
{
return view('about.contact');
}
public function show()
{
return view('about.contactshow');
}
}
This is my blade template about\contact.blade.php
:
{!! Form::open(array('action' => 'About@show', 'method' => 'post')) !!}
{!! Form::label('username','Username',array('id'=>'user','class'=>'')) !!}
{!! Form::text('username','user 1',array('id'=>'user','class'=>'', 'placeholder' => 'user 1')) !!}
{!! Form::submit('Click Me!') !!}
{!! Form::close() !!}
What am I doing wrong?
Upvotes: 4
Views: 41542
Reputation: 49
I had the same issue.
The problem was with routes/web.php
. I was building my app one step at a time, and because of that I passed a second array to my route using 'only'
like this, to make it create the index route only:
Route::resource('model', 'ModelController', [
'only' => ['index']
]);
But after creating the 'create' view, I couldn't pass data to store
function in my controller. I found out because the store
function requires an explicit route (as mentioned above). So I added it to the 'only'
array like this and it worked like a charm:
Route::resource('model', 'ModelController', [
'only' => [
'index',
'create',
'store',
]
]);
(Laravel v. 7.4.0)
Upvotes: 3
Reputation: 884
I had a similar issue but it wasnt my controller name that was wrong (web.php and actual file name were 100% correct). Due to an earlier 'refactor' - it replaced my form action/method. So my form opener looked like so:
{!! Form::open(['method'=>'POST', 'action'=>'AdminBankingDetailController', 'class'=>'m-form m-form--state']) !!}
Instead of like so (for the create view/page):
{!! Form::open(['method'=>'POST', 'action'=>'AdminBankingDetailController@store', 'class'=>'m-form m-form--state']) !!}
Make sure it has an @action on your form.
Upvotes: 0
Reputation: 82
When you get this error, it's possible that you entered the wrong spelling in the web.php or another action method. Simply go and check the spelling.
Upvotes: -1
Reputation: 337
That's all, because of routes file web.php
. Plz check out you routes file
Upvotes: 3
Reputation: 20302
I was able to solve it.
First I had to change 'action' => 'About@show'
to 'action' => 'AboutController@show'
Then I had to register all Controller Actions in routes.php:
Route::post('contact_show', [
'uses' => 'AboutController@show'
]);
Route::get('contact_create', [
'uses' => 'AboutController@create'
]);
Upvotes: 6
Reputation: 350
You're not calling the good controller!!
{!! Form::open(array('action' => 'AboutController@show', 'method' => 'post')) !!}
instead of:
{!! Form::open(array('action' => 'About@show', 'method' => 'post')) !!}
It's trying to get the action About@show but you didn't define it like this in your controller!!
Hope it helps!
Upvotes: 1