我尝试了几个小时没有成功地搜索和搞乱自己,所以我在这里。
这是我的简化控制器:
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
}
}
}
问题是当加载了get视图并且我提交了一个表单时,get页面再次被加载,好像post没有提交或工作一样。我做了一些测试,发现在提交后,代码执行甚至没有进入elseif块。
此外,
有人可以告诉我应该在哪里看看吗?
前端代码:
@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
答案 0 :(得分:1)
我现在确定导致这一切的原因。
它与在路线和uri中使用“/”有关。
由于没有遵循使用“/”的限制规则,我的一些uri最后有“/”而有些则没有。最终在某些地方造成混乱。
现在,为了使它工作,我的uri总是以“/”开头而没有“/”结束。