【问题标题】:laravel MethodNotAllowedHttpException No message errorlaravel MethodNotAllowedHttpException 无消息错误
【发布时间】:2019-01-26 19:49:01
【问题描述】:

我正在提交一个表单,但它显示了错误

MethodNotAllowedHttpException 无消息

这是我的代码。

create.blade.php

 <form method="POST" action="/Form/show">
        {{csrf_field()}}
        <div class="form-group">
            First Name : <input class="form-control" type="text" placeholder="John" name="first_name"/>
        </div>
        <div class="form-group">
            Last Name : <input class="form-control" type="text" placeholder="Wick" name="last_name"/>
        </div>
  <button type="submit" class="btn btn-default">Submit</button>
    </form>

ResourceController.php

public function show(){

    $f_data = \App\revesion_registration::all();
    return view('Form.show', compact('f_data'));
}


public function create(){
    return view('form.create');
}

public function store(){
    revesion_registration::create(request(['first_name','last_name']));
return redirect('show');

}

web.php

Route::resource('Form','ResourceController');

路线:列表

GET|HEAD | Form | Form.index |App\Http\Controllers\FormsController@index
POST     | Form | Form.store | App\Http\Controllers\FormsController@store
GET|HEAD | Form/create | Form.create | App\Http\Controllers\FormsController@create 
GET|HEAD | Form/{Form} | Form.show | App\Http\Controllers\FormsController@show

【问题讨论】:

  • 你能显示你的 php artisan route:list 结果吗?
  • 获取|头|表格 | Form.index |App\Http\Controllers\FormsController@index POST |表格 |表格商店 | App\Http\Controllers\FormsController@store GET|HEAD |形成/创建 |表单创建 | App\Http\Controllers\FormsController@create GET|HEAD |表格/{表格} |表格展示 |应用\Http\Controllers\FormsController@show |网络
  • 我还有 3 个用于更新、销毁和编辑

标签: laravel laravel-5


【解决方案1】:

在您的create.blade.php 文件中,

<form method="POST" action="{{ route('Form.store') }}">

在您的控制器存储方法中,

public function store(Request $request)
  {
    revesion_registration::create(request(['first_name','last_name']));
return redirect(route('Form.create'));

  }

【讨论】:

    【解决方案2】:

    show() 方法仅接受 GET 请求,这是您的表单尝试向 POST 发送的请求。假设您尝试在数据库中创建新记录,您应该将表单更新为:

    <form method="POST" action="Form">
    

    如果您已经添加/更新了路由,请运行命令php artisan route:clear 清除路由缓存。

    【讨论】:

    • 运行命令php artisan route:clear,确保路由缓存已经更新。
    • 用你所做的更新你的答案,以便我看到。只是说它不起作用对我没有帮助。
    • 我运行了命令 php artisan route:clear 但仍然收到错误
    • 好的。我认为问题在于您需要将表单更新为:&lt;form method="POST" action="Form"&gt;
    【解决方案3】:

    使用时

    Route::resource('routename','ControllerClassName');

    例如,我们有后模型

    Route::resource('posts','PostController');

    它将注册以下路由

    Route::get('/posts',  'PostController@index')->name('posts.index');
    Route::get('/posts/create',  'PostController@create')->name('posts.create');
    Route::post('/posts',  'PostController@store')->name('posts.store');
    Route::get('/posts/{post}',  'PostController@show')->name('posts.show');
    Route::get('/posts/{post}/edit',  'PostController@edit')->name('posts.edit');
    Route::put('/posts/{post}',  'PostController@update')->name('posts.update');
    Route::delete('/posts/{post}',  'PostController@destroy')->name('posts.destroy');
    

    现在来解决您的问题

    您的模型名称为 revesion_registration,您的表名称为 revesion_registrations

    解决方案

    你需要将路由注册为

    revesionregistrations
    

    Route::resource('revesionregistrations','RevesionRegistrationController'); in web.php

    在你的创建表单中

    <form name='add_revesionregistrations' method='post' enctype="multipart/form-data" action="{{ route('revesionregistrations.store') }}" autocomplete="off">
                        {{csrf_field()}} 
    
       <input type="text" name='name' class="form-control">
                       <input type="submit" value="Submit">
                    </form>
    

    您的问题将得到解决

    Now My Suggestion

    创建模型时不要创建小写

    不是revesion_registration

    试试php artisan make:model RevesionRegistration -a

    如果您只执行 CRED 操作,请使用 Route::resource('routename','ControllerClassName');

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-12
      • 2019-05-18
      • 1970-01-01
      • 2019-03-09
      • 1970-01-01
      • 2018-10-07
      • 2018-06-21
      • 2018-08-07
      相关资源
      最近更新 更多