0
我搜索了論壇並且看到了許多類似的問題,但沒有一個看起來解決了我的問題。我相信,因爲這是不同的:在Laravel 5.4中使用return back() - > withInput()生成MethodNotAllowedHttpException
- 表單驗證未在這一點上
- 使用的形式方法似乎並不相關(僅1後動作)
- 的路由不裹網絡中間件
下面是應用程序應該做的事情:
- 用戶(帶或不帶身份驗證)查看公共頁面的形式(display_event)
- 用戶選擇特定的票訂貨和被引導到第二個表(register_step1)
- 然後,用戶填寫人口信息儘可能多的門票正在有序
- 處理步驟(如果使用的電子郵件地址是有效用戶(在數據庫中)應該返回到步驟2中的表單),填充字段並刷新消息。否則,它會執行所需的save()操作。 (register_step2)
從web.php有關路線的位置:
Route::get('/events/{event}', '[email protected]')->name('display_event');
Route::post('/register/{event}', '[email protected]')->name('register_step1');
Route::post('/register/{event}/create', '[email protected]')->name('register_step2');
的RegistrationController.php的相關部分在這裏:
public function showRegForm (Request $request, $id) {
// Registering for an event from /event/{id}
$ticket = Ticket::find(request()->input('ticketID'));
$quantity = request()->input('quantity');
$discount_code = request()->input('discount_code');
$event = Event::find($ticket->eventID);
return view('v1.public_pages.register', compact('ticket', 'event', 'quantity', 'discount_code'));
}
和:
public function store (Request $request) {
$event = Event::find(request()->input('eventID'));
if(Auth::check()) {
$this->currentPerson = Person::find(auth()->user()->id);
}
// set up a bunch of easy-reference variables from request()->input()
$email = Email::where('emailADDR', $checkEmail)->first();
if(!Auth::check() && $email === null) {
// Not logged in and email is not in database; must create
$person = new Person;
// add person demographics from form
} elseif(!Auth::check() && $email !== null) {
// Not logged in and email is in the database;
// Should force a login -- return to form with input saved.
flash("You have an account that we've created for you.
Please attempt to login and we'll send you a password to your email address.", 'warning');
return back()->withInput();
} elseif(Auth::check() && ($email->personID == $this->currentPerson->personID)) {
// the email entered belongs to the person logged in; ergo in DB
$person = $this->currentPerson;
// add person demographics from form
} elseif(Auth::check() && ($email->personID != $this->currentPerson->personID)) {
// someone logged in is registering for someone else in the DB
$person = Person::find($email->personID);
// add person demographics from form
} else {
// someone logged in is registering for someone else NOT in the DB
$person = new Person;
// add person demographics from form
}
// do more stuff...
$reg = new Registration; (set up a registration record)
}
重定向生成一個GET請求。你真的需要通過'POST'來顯示你的註冊表嗎? – apokryfos
該帖子正在處理來自表單1的輸入,然後顯示。我想我可以分開,以便處理步驟是一個帖子,然後重定向到get顯示下一個表單。我會嘗試的,如果解決了這個問題,請給出評論的答案(假設可能)。 :-) – Phil
不,這是不可能的,但我的評論也只是一個評論,而不是一個實際的答案,但是如果它對你有用,回答你自己的問題,因爲它可以幫助其他人。 – apokryfos