Post方法上的MethodNotAllowedHttpException

时间:2019-02-04 17:55:08

标签: php laravel

Laravel入门,尝试发布到我的页面之一时遇到问题。

我正在使用Postman向我的/ clock页面创建发布请求。

帖子将发送一个具有单个字段的简单Json:

POST body

以下是该帖子的标题:

POST headers

我的路线当前位于routes / api.php文件夹中,并且包含以下内容:

while(!tmpList.isEmpty()){
    Iterator<Term> iter = tmpList.iterator();

    Term tmpTerm = null;
    while(iter.hasNext()){
        tmpTerm = iter.next();
        if(condition){
            double tmpTermCoeff = tmpTerm.getCoeff();
        }
    }
    simpleP.addTerm(tmpTerm);
}

链接到<pre> <?php use Illuminate\Http\Request; /* |-------------------------------------------------------------------------- | API Routes |-------------------------------------------------------------------------- | | Here is where you can register API routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | is assigned the "api" middleware group. Enjoy building your API! | */ Route::middleware('auth:api')->get('/user', function (Request $request) { return $request->user(); }); Route::post('/json', 'FormController@post'); Route::post('/clock', 'PayrollController@index'); 的控制器的代码如下:

app/Http/Controller/PayrollController.php

当我在Postman中执行帖子时,这是我得到的错误:

    <?php

    namespace App\Http\Controllers;


    use GuzzleHttp\Client;
    use App\Company;
    use Response;
    use Illuminate\Support\Facades\App;
    use Illuminate\Support\Facades\DB;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Auth;

    class PayrollController extends Controller
    {

        function __construct()
        {
        }

        public function index()
        {
        }

1 个答案:

答案 0 :(得分:0)

问题是您在get Request上定义了发布路线,定义了使用发布标头的请求,如果使用表格,则更改发布方法,如果不查询数据库,则将路由更改为

 Route::get('/clock', 'PayrollController@index');