我已经搜索了论坛并看到了很多类似的问题,但似乎没有一个问题可以解决我的问题。我相信这是不同的,因为:
这是应用程序应该做的事情:
web.php的相关路线如下:
Route::get('/events/{event}', 'EventController@show')->name('display_event');
Route::post('/register/{event}', 'RegistrationController@showRegForm')->name('register_step1');
Route::post('/register/{event}/create', 'RegistrationController@store')->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)
}
答案 0 :(得分:2)
我接受了@ apokryfos评论中指出的建议,并将表单解析后显示脚本从POST更改为get。
redirect() - > back()显然总是一个method = get,这是MethodNotAllowedHttpException的原因。在使用Laravel的~2周内,我还没有遇到过这个事实。