开始使用Laravel,我在尝试发布到我的一个页面时遇到了问题。
我正在使用Postman创建到我的/clock页面的post请求。
这篇文章发送了一个简单的Json,只有一个字段:
以下是《华盛顿邮报》的标题:
我的路由当前位于routes/api.php文件夹中,包含以下内容:
<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
的控制器代码如下所示:
<?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()
{
}
当我在Postman中执行post时,这是我得到的错误:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: in file /var/www/html/oit_laravel1/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php on line 255
Stack trace:
1. Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException->() ...
发布于 2019-02-04 19:04:54
问题是您在get请求上定义了post路由,将您的请求定义为使用post标头,如果使用表单,则将方法更改为post,如果不查询数据库,则将路由更改为
Route::get('/clock', 'PayrollController@index');
https://stackoverflow.com/questions/54521733
复制