laravel-5.6中的MethodNotAllowedHttpException

时间:2018-04-08 11:32:14

标签: php laravel methods routes laravel-5.6

我正在尝试使用方法'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" width="100%">
    <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');



});
  

AttendanceController.php

/**
*
*checkout
**/

public function checkout(Request $request)
{
    return $request->all();
}

2 个答案:

答案 0 :(得分:0)

试试这个

Route::post('checkout', 'Admin\HR\AttendanceController@checkout')->name('checkout');

<form action="{{ route('admin.checkout') }}" method="POST">

答案 1 :(得分:0)

在web.php文件中创建路由

Route::get('/', 'LoginController@index');

在Controller中添加

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()}}