Laravel Route Post不允许 - php

我试图在laravel中创建一个路由发布,我使用“ get”,它工作正常,但是当我使用“ post”,“ delete”等不起作用时,它返回错误500(内部服务器错误)。

有我的路线代码

    Route::post('Register' ,function(){
    return "Hello World";
});

我正在使用Google Chrome扩展程序“高级REST客户端”执行一个“发布”,这给了我该信息

Request headers 
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Content-Type: application/json 
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: XSRF-TOKEN=


Response headers 
Host: localhost:60967
Connection: close
X-Powered-By: PHP/5.5.12
Cache-Control: no-cache, private 
date: Wed, 23 Dec 2015 01:51:29 GMT
Content-type: text/html

我正在寻找几个小时,但找不到解决方案。

参考方案

您的XSRF令牌丢失。默认情况下,新的Laravel应用程序中的所有路由都已启用CSRF保护。

您将需要通过设置_token将有效令牌添加到POST请求标头中,或添加到POST数据本身中。

如果您只需要测试POST路由本身,则可以临时禁用CSRF中间件,或根据情况应用它。

禁用
app / Http / Kernel.php

protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        //\App\Http\Middleware\VerifyCsrfToken::class, //Comment this out
    ],
    'api' => [
        'throttle:60,1',
    ],
];
/**
 * The application's route middleware.
 *
 * These middleware may be assigned to groups or used individually.
 *
 * @var array
 */
protected $routeMiddleware = [
    'auth' => \App\Http\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];

启用为路由中间件
app / Http / Kernel.php

protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    ],
    'api' => [
        'throttle:60,1',
    ],
];
/**
 * The application's route middleware.
 *
 * These middleware may be assigned to groups or used individually.
 *
 * @var array
 */
protected $routeMiddleware = [
    'auth' => \App\Http\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    'csrf' => \App\Http\Middleware\VerifyCsrfToken::class, //Move it here
];

如何在Laravel中通过路由名称获取带有名称空间的路由? - php

我有一条路线如下Route::group(['prefix' => '/entry', 'namespace' => 'acme'], function() { Route::get('add', [ 'uses' => …

PHP Laravel从另一个驱动器读取文件 - php

我目前正在学习Laravel。我想知道是否有一种方法可以在Laravel中使用Storage::从另一个硬盘访问文件(使用Windows)。例如,我在驱动器C:上安装了带有Laravel的Xampp,但是我想访问网站目录之外的E:上的文件。我试过使用Storage::files('E:')和File::files('E:…

检查对象是否已在集合中-Laravel - php

当我循环一系列不同的结果时,我希望将对象添加到新集合中。查询:$osRed = Item::where('category', 'Hardware') ->where(function ($query) { $query->where('operating_system', '…

laravel Hash::make继续给出不同的结果 - php

我想在laravel 4中使用身份验证我改了桌子和莫贝尔的名字当用户注册时,我拥有密码并将其保存,哈希为:$password = Hash::make(Input::get('password')); 然后当用户登录时,我想先对他/她进行身份验证。我这样做是这样的:if (Auth::attempt(array('usernam…

Laravel打印日志 - php

我正在尝试在控制台上打印日志:我输入了:use Log; 然后在控制器中使用 Log::info('test log'); 但它不打印任何日志。 参考方案 我认为您需要在运行后检查storage/logs/laravel.logLog::info('test log'); 希望这对您有帮助