Laravel 提交表单后如何重定向到其他页面
如何在使用控制器提交表单后重定向到其他页面。表单工作正常,但是当我使用这样的代码时,我会得到一个空白页,如果我使用Laravel 提交表单后如何重定向到其他页面,laravel,redirect,Laravel,Redirect,如何在使用控制器提交表单后重定向到其他页面。表单工作正常,但是当我使用这样的代码时,我会得到一个空白页,如果我使用 return view('leave.signUp'); 它可以工作,但仍然保留在表单的页面中,我希望它被重定向到另一个页面 public function index(Request $request) { if($request->isMethod('POST')){ $employee = new Employee; $emp
return view('leave.signUp');
它可以工作,但仍然保留在表单的页面中,我希望它被重定向到另一个页面
public function index(Request $request)
{
if($request->isMethod('POST')){
$employee = new Employee;
$employee->lname = $request->input('lname');
$employee->fname = $request->input('fname');
$employee->oname = $request->input('oname');
$employee->employee_id = $request->input('staffId');
$employee->college = $request->input('college');
//$employee->salary_level = $request->input('salaryGradeLevel');
$employee->employee_type = $request->input('staffType');
$employee->employee_category= $request->input('staffCategory');
$employee->date_of_first_appointment= $request->input('dateOfFirstAppointment');
$employee->date_of_last_appointment= $request->input('dateOfLastAppointment');
$employee->country = $request->input('country');
$employee->gender = $request->input('gender');
$employee->title = $request->input('title');
$employee->marital_status = $request->input('maritalStatus');
$employee->email = $request->input('email');
$employee->phone_number = $request->input('phoneNumber');
$employee->date_of_birth = $request->input('dateOfBirth');
$employee->place_of_birth = $request->input('placeOfBirth');
$employee->religion = $request->input('religion');
$employee->origin = $request->input('stateOfOrigin');
$employee->local_government_area = $request->input('localGovernmentArea');
$employee->address = $request->input('address');
$employee->permanent_address = $request->input('permanentAddress');
$employee->extra_curicullar_activities = $request->input('extraCuricularActivities');
$employee->save();
$nextOfKin = new NextOfKin;
$nextOfKin->employee_id = $employee->employee_id;
$nextOfKin->title = $request->input('Ntitle');
$nextOfKin->surname = $request->input('Nsurname');
$nextOfKin->firstname = $request->input('Nfirstname');
$nextOfKin->othername = $request->input('Nothername');
$nextOfKin->relationship = $request->input('Nrelationship');
$nextOfKin->email = $request->input('Nemail');
$nextOfKin->phone_number = $request->input('NphoneNumber');
$nextOfKin->contact_address = $request->input('Naddress');
$nextOfKin->save();
return redirect(route('application'));
}
}
这是我的web.php
Route::match(['post','get'],'application', 'LeavessController@index');
Route::match(['post','get'],'signUp', 'signUpsController@index');
Route::get('approved', 'LeavesController@getLeaveApproved');
Route::match(['post','get'], 'leaveType', 'LeavesController@getleaveType');
Route::match(['post','get'], 'leaveDepartment', 'LeavesController@getleaveDepartment');
Route::get('allLeave', 'LeavesController@getallLeave');
Route::get('leaveViewDetails', 'LeavesController@getleaveViewDetails');
Route::get('/get-leave-days/{leaveType}', 'LeavesController@getLeaveDays');
要重定向到“简单”URL,请使用:
(将“主页/仪表板”替换为要重定向到的实际URL)
要重定向到命名路由,请使用:
return redirect()->route('login');
(其中,login
是您的路线名称)
route()
的参数是您在路由中使用name(…)
除此之外,我建议您阅读关于控制器的laravel文档:
索引
仅用于返回数据库条目。要将数据插入数据库,请使用store
如果你得到一个“空白”页面,最好检查一下你的Laravel日志,看看是什么导致了错误。我猜这是对route()
part@kerbholz请问您建议我怎么走这条路线;带有返回重定向(“应用程序”);代码跳过了我存储数据的所有表单,直接转到url。我希望它在重定向之前排除控制器中的代码。感谢您未定义路由[应用程序]。当我使用return redirect()->route('login');在web.php
中是否有名为application
的路由?具有->名称('application')
的路由?看起来你没有。请hw我创建一个名称路由,一直在尝试,如你所说,但我没有得到它。事实上,我对拉雷维尔是新来的。请。G更改您的routes/web.php
此行Route::match(['post','get'],'application','LeavessController@index');代码>到路由::匹配(['post','get'],'application','LeavessController@index')->名称(“应用程序”)代码>。有关更多信息,请查看:
return redirect()->route('login');
return redirect()->route('application');