从AMP-HTML联系人表单向Laravel 5.4发出XHR请求。500错误

从AMP-HTML联系人表单向Laravel 5.4发出XHR请求。500错误,laravel,symfony,xmlhttprequest,laravel-5.4,amp-html,Laravel,Symfony,Xmlhttprequest,Laravel 5.4,Amp Html,我在从AMP表单向Laravel5.4控制器发出ajax请求时遇到了这个错误 这是AMP-HTML表单: <form method="post" action-xhr="/mobile/help-post" target="_top" on="submit:msg.hide;submit-success:success-lightbox;submit-error:error-lightbox"> <fieldset> &l

我在从AMP表单向Laravel5.4控制器发出ajax请求时遇到了这个错误

这是AMP-HTML表单:

<form method="post"
    action-xhr="/mobile/help-post"
    target="_top"
    on="submit:msg.hide;submit-success:success-lightbox;submit-error:error-lightbox">

    <fieldset>
        <span>Your name</span>
        <input placeholder="Write here.." type="text" name="name" id="name" required>
    </fieldset>

    <fieldset>  
        <span>Your email</span>
        <input placeholder="Write here.." type="email" name="email" id="email" required>
    </fieldset>

    <fieldset>  
        <span>Your message</span>
        <textarea placeholder="Write here" name="message" id="email" required></textarea>
    </fieldset>

    <fieldset class="btn">  
        <input class="btn-primary" type="submit" value="Send Help Request »">
    </fieldset>

    <!--Error Messages-->
    <span visible-when-invalid="valueMissing" validation-for="name"></span>
    <span visible-when-invalid="valueMissing" validation-for="email"></span>
    <span visible-when-invalid="valueMissing" validation-for="message"></span>

    <span visible-when-invalid="typeMismatch" validation-for="name"></span>
    <span visible-when-invalid="typeMismatch" validation-for="email"></span>
    <span visible-when-invalid="typeMismatch" validation-for="message"></span>
    <!--End Error Messages-->

    <div submit-success>
        <template type="amp-mustache">
            Success! Sit tight and we'll get back to you soon!
        </template>
    </div>
    <div submit-error>
        <template type="amp-mustache">
            Oops!, We apologies something went wrong. Please try again later.
        </template>
    </div>
</form>
这是路线:

Route::prefix('mobile')->group(function(){
    Route::get('/help', 'PagesController@getHelp')->name('help');
    Route::post('/help-post', 'PagesController@postHelp')->name('help-post');
}
我从服务器收到此500错误:

类型错误:参数1传递给 Illumb\Session\Middleware\StartSession::AddCookietoreResponse()必须 是Symfony\Component\HttpFoundation\Response的实例,实例 给定的照明\路由\重定向器的个数,在中调用 C:\xampp\htdocs**\vendor\laravel\framework\src\light\Session\Middleware\StartSession.php 在线72

我已根据AMP-HTML的要求添加了此全局中间件:

<?php namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class AddHeaders
{
    public function handle(Request $request, Closure $next)
    {
        $response = $next($request);
        $response->header("Access-Control-Allow-Origin", '*'); 
        $response->header("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
        $response->header("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token");
        $response->header("Access-Control-Expose-Headers", "AMP-Access-Control-Allow-Source-Origin");
        $response->header("AMP-Access-Control-Allow-Source-Origin", 'http://localhost:8000');
        $response->header("Access-Control-Allow-Credentials", "true");

        return $response;
    }
}
它抱怨
addCookietoreResponse
接收重定向程序而不是响应对象

这是框架(namespace illumb\Session\Middleware\StartSession.php)中调用AddCookietoreResponse的部分-请阅读我在代码中的注释:

public function handle($request, Closure $next)
    {
        $this->sessionHandled = true;

        // If a session driver has been configured, we will need to start the session here
        // so that the data is ready for an application. Note that the Laravel sessions
        // do not make use of PHP "native" sessions in any way since they are crappy.
        if ($this->sessionConfigured()) {
            $request->setLaravelSession(
                $session = $this->startSession($request)
            );

            $this->collectGarbage($session);
        }

        $response = $next($request);

        // Again, if the session has been configured we will need to close out the session
        // so that the attributes may be persisted to some storage medium. We will also
        // add the session identifier cookie to the application response headers now.
        if ($this->sessionConfigured()) {
            $this->storeCurrentUrl($request, $session);

            $this->addCookieToResponse($response, $session);-->LOOK HERE: so is $response here a Redirector object ??????? But it's $response = $next($request); !!!!!!
        }

        return $response;
    }

我非常怀疑框架中是否有什么东西。但是,我不知道我在哪里返回了重定向程序而不是响应。从表单到控制器再到表单,这是一个简单的顺序

您忘记添加
csrf\u字段()


{{csrf_field()}}
你的名字
你的电子邮件
你的信息
成功!坐好,我们很快会给你回复的!
哎呀!,我们为出了问题而道歉。请稍后再试。

您忘记添加
csrf\u字段()


{{csrf_field()}}
你的名字
你的电子邮件
你的信息
成功!坐好,我们很快会给你回复的!
哎呀!,我们为出了问题而道歉。请稍后再试。

您的csrf_字段()在哪里?我刚刚添加了它,现在可以工作了:D谢谢!您的代码是否使用“span visible when invalid=“valueMissing”验证前端的文本区域?因为它似乎只为我验证输入,而不是文本区域。你的csrf_字段()在哪里?我刚刚添加了它,它现在可以工作了:D感谢堆!您的代码是否使用“span visible when invalid=“valueMissing”验证前端的文本区域?因为它似乎只为我验证输入,而不是文本区域
in StartSession.php (line 170)
at StartSession->addCookieToResponse(object(Redirector), object(Store))
public function handle($request, Closure $next)
    {
        $this->sessionHandled = true;

        // If a session driver has been configured, we will need to start the session here
        // so that the data is ready for an application. Note that the Laravel sessions
        // do not make use of PHP "native" sessions in any way since they are crappy.
        if ($this->sessionConfigured()) {
            $request->setLaravelSession(
                $session = $this->startSession($request)
            );

            $this->collectGarbage($session);
        }

        $response = $next($request);

        // Again, if the session has been configured we will need to close out the session
        // so that the attributes may be persisted to some storage medium. We will also
        // add the session identifier cookie to the application response headers now.
        if ($this->sessionConfigured()) {
            $this->storeCurrentUrl($request, $session);

            $this->addCookieToResponse($response, $session);-->LOOK HERE: so is $response here a Redirector object ??????? But it's $response = $next($request); !!!!!!
        }

        return $response;
    }
<form method="post"
    action-xhr="/mobile/help-post"
    target="_top"
    on="submit:msg.hide;submit-success:success-lightbox;submit-error:error-lightbox">
      {{csrf_field()}}
    <fieldset>
        <span>Your name</span>
        <input placeholder="Write here.." type="text" name="name" id="name" required>
    </fieldset>

    <fieldset>  
        <span>Your email</span>
        <input placeholder="Write here.." type="email" name="email" id="email" required>
    </fieldset>

    <fieldset>  
        <span>Your message</span>
        <textarea placeholder="Write here" name="message" id="email" required></textarea>
    </fieldset>

    <fieldset class="btn">  
        <input class="btn-primary" type="submit" value="Send Help Request »">
    </fieldset>

    <!--Error Messages-->
    <span visible-when-invalid="valueMissing" validation-for="name"></span>
    <span visible-when-invalid="valueMissing" validation-for="email"></span>
    <span visible-when-invalid="valueMissing" validation-for="message"></span>

    <span visible-when-invalid="typeMismatch" validation-for="name"></span>
    <span visible-when-invalid="typeMismatch" validation-for="email"></span>
    <span visible-when-invalid="typeMismatch" validation-for="message"></span>
    <!--End Error Messages-->

    <div submit-success>
        <template type="amp-mustache">
            Success! Sit tight and we'll get back to you soon!
        </template>
    </div>
    <div submit-error>
        <template type="amp-mustache">
            Oops!, We apologies something went wrong. Please try again later.
        </template>
    </div>