laravel-5.6 中的 MethodNotAllowedHttpException
Posted
技术标签:
【中文标题】laravel-5.6 中的 MethodNotAllowedHttpException【英文标题】:MethodNotAllowedHttpException in laravel-5.6 【发布时间】:2018-09-17 22:23:15 【问题描述】:我正在尝试使用“POST”方法提交表单,但得到MethodNotAllowedHttpException
我知道出现此错误的一些可能原因,并且还在互联网上搜索了可能的解决方案。除了这个之外,我的项目的所有其他形式都运行良好。我找不到出现此常见错误的原因。有人可以帮我找出解决方案吗?
表格
<form action=" url('admin/checkout') " method="POST">
@csrf
<div class="row">
<div class="col-sm-6 offset-sm-3">
<label class="m-t-20">Now time</label>
<div class="input-group">
<input name="outtime" class="form-control" id="single-input" value="" placeholder="Now" required>
<span class="input-group-btn">
<button type="submit" id="check-minutes" class="btn waves-effect waves-light btn-warning">Check Out</button>
</span>
@if ($errors->has('outtime'))
<small class="error"> $errors->first('outtime') </small>
@endif
</div>
</div>
</div>
<br>
<table id="flow-table" class="display nowrap mytable" cellspacing="0" >
<thead>
<tr>
<th style="width: 15px;">#</th>
<th class="check">
<div class="checkbox">
<label>
<input type="checkbox" id="flowcheckall" />
<i class="input-helper"></i>
<span><strong> All</strong></span>
</label>
</div>
</th>
<th class="text-left">Name</th>
<th>Cord No</th>
<th>Section</th>
<th>Designation</th>
</tr>
</thead>
<tbody>
@forelse($employees as $employee)
<tr class="text-center">
<td> $loop->index + 1 </td>
<td style="max-width: 30px;">
<div class="checkbox text-center">
<label>
<input type="checkbox" name="employee_id[]" class="check" id="checkall" value=" $employee->employee_id " />
<i class="input-helper"></i>
</label>
</div>
</td>
<td class="text-left"> $employee->name </td>
<td> $employee->card_no </td>
<td> ucwords($employee->section) </td>
<td> ucwords($employee->designation) </td>
</tr>
@empty
@endforelse
</tbody>
</table>
</form>
web.php
#Admin Routes
Route::get('admin', 'Admin\LoginController@showLoginForm')->name('admin.login');
Route::post('admin', 'Admin\LoginController@login');
Route::post('admin-password/email', 'Admin\ForgotPasswordController@sendResetLinkEmail')->name('admin.password.email');
Route::get('admin-password/reset', 'Admin\ForgotPasswordController@showLinkRequestForm')->name('admin.password.request');
Route::post('admin-password/reset', 'Admin\ResetPasswordController@reset');
Route::get('admin-password/reset/token', 'Admin\ResetPasswordController@showResetForm')->name('admin.password.reset');
Route::group(['prefix' => 'admin', 'middleware' => ['auth:admin'], 'as' => 'admin.'], function ()
# Dashboard / Index
Route::get('home', array('as' => 'home','uses' => 'Admin\AdminController@index'));
Route::get('change-password', array('as' => 'change-password','uses' => 'Admin\AdminController@changePassword'));
Route::put('change-password', array('as' => 'change-password','uses' => 'Admin\AdminController@updatePassword'));
// HR (Section)
Route::resource('section', 'Admin\HR\SectionController');
// HR (Designation)
Route::resource('designation', 'Admin\HR\DesignationController');
// HR (Salary Grade)
Route::resource('salary-grade', 'Admin\HR\SalaryGradeController');
// HR (Employee)
Route::resource('employees', 'Admin\HR\EmployeeController');
//HR (Employee cv download)
Route::get('cv-download/id', 'Admin\HR\EmployeeController@cvDownload');
// HR (Attendance)
Route::resource('attendances', 'Admin\HR\AttendanceController');
Route::post('attendances/searched-employees', 'Admin\HR\AttendanceController@searchedEmployees');
Route::get('today-checked-in', array('as' => 'today-checked-in', 'uses' => 'Admin\HR\AttendanceController@checkedIn'));
Route::post('checkout', 'Admin\HR\AttendanceController@checkout');
//HR (Leave Type)
Route::resource('leave-types', 'Admin\HR\LeaveTypeController');
//HR (Leave Application)
Route::resource('leave-application', 'Admin\HR\LeaveApplicationController');
Route::post('leave-application/searched-employees', 'Admin\HR\LeaveApplicationController@searchedEmployees');
Route::get('leave-application/id/create', 'Admin\HR\LeaveApplicationController@create');
Route::get('leave-application-download/id', 'Admin\HR\LeaveApplicationController@applicationDownload');
//HR (Holidays)
Route::resource('holidays', 'Admin\HR\HolidayController');
//HR (Promotions)
Route::resource('promotions', 'Admin\HR\PromotionController');
Route::get('promotions/id/create', 'Admin\HR\PromotionController@create');
Route::post('promotions/searched-employees', 'Admin\HR\PromotionController@searchedEmployees');
Route::get('promotions/update/id', 'Admin\HR\PromotionController@');
//HR (Payroll Provident Fund)
Route::resource('provident-fund', 'Admin\HR\ProvidentFundController');
Route::post('provident-fund/searched-employees', 'Admin\HR\ProvidentFundController@searchedEmployees');
Route::get('provident-fund/id/create', 'Admin\HR\ProvidentFundController@create');
//HR (Payroll Advance Salary)
Route::resource('advance-salary', 'Admin\HR\AdvanceSalaryController');
Route::post('advance-salary/searched-employees', 'Admin\HR\AdvanceSalaryController@searchedEmployees');
Route::get('advance-salary/id/create', 'Admin\HR\AdvanceSalaryController@create');
//HR (Payroll-Salary)
Route::group(['prefix' => 'salary', 'as' => 'salary.'], function ()
//make salary
Route::get('make-salary', array('as' => 'make-salary', 'uses' => 'Admin\HR\SalaryController@makeSalaryIndex'));
Route::post('make-salary-employees-list', array('as' => 'make-salary-employees-list', 'uses' => 'Admin\HR\SalaryController@getMakeSalaryEmployeeList'));
Route::post('make-salary-save/id', array('as' => 'make-salary-save', 'uses' => 'Admin\HR\SalaryController@makeSalarySave'));
//make payment
Route::get('make-payment', array('as' => 'make-payment', 'uses' => 'Admin\HR\SalaryController@makePaymentSearch'));
Route::post('make-payment-employees-list', array('as' => 'make-payment-employees-list', 'uses' => 'Admin\HR\SalaryController@getMakePaymentEmployeeList'));
Route::get('employee/id', array('as' => 'employee', 'uses' => 'Admin\HR\SalaryController@makeEmployeeSalary'));
Route::put('change-payment-status/id', array('as' => 'change-payment-status', 'uses' => 'Admin\HR\SalaryController@changePaymentStatus'));
//generate payslip
Route::get('payslip', array('as' => 'payslip', 'uses' => 'Admin\HR\SalaryController@generatePayslip'));
Route::post('payslip-search', array('as' => 'payslip-search', 'uses' => 'Admin\HR\SalaryController@payslipSearch'));
);
/*Accounts Part*/
//Accounts (Groups)
Route::resource('groups', 'Admin\Accounts\GroupController');
//Accounts (Groups)
Route::resource('companies', 'Admin\Accounts\CompanyController');
//Accounts (Customers)
Route::resource('customers', 'Admin\Accounts\CustomerController');
//Accounts (Suppliers)
Route::resource('suppliers', 'Admin\Accounts\SupplierController');
);
出勤控制器.php
/**
*
*checkout
**/
public function checkout(Request $request)
return $request->all();
【问题讨论】:
向我们展示您的完整路线web.php
更新了 web.php
尝试使用 php artisan route:clear 清除路由缓存
您是通过正常点击按钮进行提交还是涉及到任何javascript?
是的,我正在正常提交。
【参考方案1】:
试试这个
Route::post('checkout', 'Admin\HR\AttendanceController@checkout')->name('checkout');
<form action=" route('admin.checkout') " method="POST">
【讨论】:
你检查了你在你的 route.php 文件中的所有路线检查天气你有你的路线php artisan route:list
【参考方案2】:
在 web.php 文件中创建路由
Route::get('/', 'LoginController@index');
在控制器中添加
public function index()
$postHeader = Request::header(); // HEADER Data
$postData = Request::all();
if(!empty($postData))
echo'<pre>';print_r($postData); die;
不要忘记在你的视图中添加 crf 令牌
<form name="" action="login" method="POST">
csrf_field()
【讨论】:
以上是关于laravel-5.6 中的 MethodNotAllowedHttpException的主要内容,如果未能解决你的问题,请参考以下文章
如何通过 laravel 5.6 中的角色保护用户管理区域?