我尝试了几个小时的搜索和困惑,但没有成功,所以我在这里。
这是我的简化 Controller :
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
}
}
}
问题是当加载获取 View 并提交表单时,获取页面会再次加载,就好像帖子未提交或未工作一样。我做了一些测试,发现提交后,代码执行甚至没有进入elseif block 。
此外,
- 代码在本地开发环境中完美运行。
- 其他 Controller 也可以进行发布,不会出现问题。其他 Controller 不会在 __construct 中注入(inject)服务 obj。
- 我查看了日志文件,它不包含任何有关 这。日志级别设置为调试。
有人可以告诉我我应该看哪里吗???
前端代码:
@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
最佳答案
我现在确定了造成这一切的原因。
这与路由和uri中使用“/”有关。
由于没有遵循使用“/”的限制规则,我的一些uri末尾有“/”,有些则没有。最终在某些地方造成困惑。
现在,为了使其正常工作,我的 uri 始终以“/”开头,以“/”结尾。
关于Laravel post 提交不在生产环境中工作,但在本地开发中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42444469/