Action App \ Http \ Controllers \ Controller @ action未定义

时间:2017-02-11 21:57:29

标签: php laravel laravel-5.2

我想提交一个表单,但即使定义了函数Action App\Http\Controllers\About@show not defined,我总是得到show

<?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');
    }

}

这是我的刀片模板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() !!}

我做错了什么?

6 个答案:

答案 0 :(得分:4)

我能够解决它。 首先,我必须将'action' => 'About@show'更改为'action' => 'AboutController@show'

然后我必须在 routes.php

中注册所有控制器操作
Route::post('contact_show', [
    'uses' => 'AboutController@show'
  ]);

Route::get('contact_create', [
    'uses' => 'AboutController@create'
  ]);

答案 1 :(得分:3)

我有同样的问题。

问题出在routes/web.php上。我一次只构建一个应用程序,因此我像这样使用'only'将第二个数组传递给我的路由,以使其仅创建索引路由:

Route::resource('model', 'ModelController', [
     'only' => ['index']
]);

但是在创建“创建”视图之后,我无法将数据传递到控制器中的store函数。我发现是因为store函数需要一条显式路由(如上所述)。因此,我将其像这样添加到'only'数组中,它的工作原理就像一个魅力:

Route::resource('model', 'ModelController', [
    'only' => [
        'index',
        'create',
        'store',
    ]
]);

(Laravel v。7.4.0)

答案 2 :(得分:1)

你没有给好控制器打电话!!

{!! Form::open(array('action' => 'AboutController@show', 'method' => 'post')) !!}

而不是:

{!! Form::open(array('action' => 'About@show', 'method' => 'post')) !!}

它试图获得关于@ show的动作但你没有在你的控制器中定义它!

希望它有所帮助!

答案 3 :(得分:1)

全部,因为路线文件web.php。 Plz检查你路线文件

答案 4 :(得分:0)

我有一个类似的问题,但不是我的控制器名称错误(web.php和实际文件名均为100%正确)。由于早期的“重构”,它取代了我的表单操作/方法。 所以我的表单打开器看起来像这样:

{!! Form::open(['method'=>'POST', 'action'=>'AdminBankingDetailController', 'class'=>'m-form m-form--state']) !!}

(对于创建视图/页面)不是这样:

{!! Form::open(['method'=>'POST', 'action'=>'AdminBankingDetailController@store', 'class'=>'m-form m-form--state']) !!}

确保您的表单上有@ action

答案 5 :(得分:-1)

当您收到此错误时,您可能在web.php或其他操作方法中输入了错误的拼写错误。只需去检查拼写。