【问题标题】:Laravel post submit not working in production but works in local developmentLaravel post submit 不在生产环境中工作,但在本地开发中工作
【发布时间】:2017-07-15 15:06:40
【问题描述】:

我尝试在自己周围搜索和搞砸了几个小时都没有成功,所以我在这里。

这是我的简化控制器:

class SettingsController extends Controller
{
    protected $emailService;
    protected $prospectEmailService;

    public function __construct(EmailServiceInterface $emailService, ProspectEmailServiceInterface $prospectEmailService) {
        $this->middleware('auth');
        $this->emailService = $emailService;
        $this->prospectEmailService = $prospectEmailService;
    }
    public function pEmails(Request $request)
    {
        if ($request->isMethod('get'))
        {
            // do something and load a view - get specific view
        }
        elseif ($request->isMethod('post')
        {
            // do something and load a post specific view
        }
    }
}

问题是当获取视图被加载并且我提交一个表单时,获取页面被再次加载,就好像帖子没有提交或工作一样。我做了一些测试,发现提交后,代码执行甚至没有进入elseif块。

另外,

  1. 代码在本地开发环境中完美运行。
  2. 其他控制器可以在没有问题的情况下进行发布。其他控制器不会在 __construct 中注入服务 obj。
  3. 我查看了日志文件,它不包含任何关于 这。日志级别设置为调试。

有人可以告诉我应该看哪里吗???

前端代码:

@extends('layouts.content')
@section('title', 'Prospects Email Settings')

@section('content')
    <div id='content'>
        <h2>Prospects Email Settings</h2>
        <div>
            <p>Note:</p>


            <h4>Current effective settings: </h4>
            <p>Schedule start date and time: {{ $currentSetting->start_dt }} </p>
            <p>Sending interval: {{ $currentSetting->span }} days</p>
            <p>Email sequence: {{ $currentSetting->email_sequence }}</p>

            <form action='/settings/prospectsEmails/' method='post'> 
                {{ csrf_field() }}      

                <h4>Create new prospects email settings below:</h4>
                <label>Schedule starting date and time: </label>
                <input type='datetime-local' name='startdt'>
                <br><br>
                <label>Sending interval (days): </label>
                <select name='interval'>
                    <option value="7">1 week</option>
                    <option value="14">2 weeks</option>
                    <option value="21">3 weeks</option>
                    <option value="28">4 weeks</option>
                </select>
                <br><br>
                <label>Specify email sequence</label>
                <br><br>
                <div>
                    @for ($i = 1; $i < 16; $i++)
                        <label>Email {{$i}}:</label>
                        <select name="email_{{ $i }}">
                            <option value="0">---</option>
                            @foreach ($emails as $email)
                                <option value="{{ $email->Email_ID }}">{{ $email->Email_ID }}: {{ $email->subject }}</option>
                            @endforeach
                        </select>
                        <br><br>
                    @endfor
                </div>
                <label>Schedule the first email right away:</label>
                <input type="radio" name="start_schedule" value="yes"> Yes
                <input type="radio" name="start_schedule" value="no" checked="checked"> No
                <br><br>
                <input type="submit" value="Create/update Email Sequence" />
                <br><br>
            </form>

            @if ($method == 'post')
                <h3>{{ $msg }}<h3>
            @endif
        </div>
    </div>
@endsection

【问题讨论】:

  • 在您的测试中,是否调用了 pEmails 函数?你能把这个的前端贴出来吗?视图。
  • 请显示使用你的 routes/web.php 文件。
  • 我看到这里有两个错别字elseif ($request-&gt;isMethod('post'):else和if之间有空格,需要关闭条件块。这是代码中的错字还是发布时的错字? :)
  • 致 Chris Cousins:是的,我确信 pEmail 会在 get 块中被调用。我通过返回一个简单的 get 视图对其进行了测试。问题是提交表单时,elseif 块中的代码永远不会被调用。
  • 前端代码:

标签: laravel post service production


【解决方案1】:

我现在确定造成这一切的原因。

这与在路由和uri中使用“/”有关。

由于不遵循使用“/”的限制规则,我的一些 uri 末尾有“/”,而有些则没有。最终在某些地方造成混乱。

现在,为了让它工作,我的 uri 总是以“/”开头,不带“/”结束。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-16
    • 2018-03-23
    • 2019-08-17
    • 1970-01-01
    • 1970-01-01
    • 2023-01-30
    • 2012-08-16
    • 2020-08-25
    相关资源
    最近更新 更多