Laravel 5.8空白页面中的表单更新结果,并在地址栏中显示提交的数据

问题描述 投票:0回答:1

我正在使用简单的laravel形式。我无法更新表单,因为提交表单数据显示在地址栏中且未进入控制器功能。找不到代码中的任何问题。尝试了所有这些解决方案,但是没有运气。感谢您的帮助。

web.php

   Route::get('/', function () {
     return view('auth.login');
   });

   Auth::routes();
   Route::get('/home', 'HomeController@index')->name('home');
     Route::group(['middleware' => 'superadmin'], function () {
      Route::resource('departments', 'DepartmentController');
   });

edit.blade.php

   <form id="deptform" data-parsley-validate class="form-horizontal form-label-left" action=" 
           {{route('departments.update',$department->id)}}" method="patch">
                 @csrf
                 @method('PATCH')
                  <div class="item form-group">
                    <label class="col-form-label col-md-3 col-sm-3 label-align" for="dept_name"> Department Name <span class="required">*</span>
                    </label>
                    <div class="col-md-6 col-sm-6 ">
                      <input type="text" id="name" required="required" class="form-control " name="dept_name" value="{{ $department->dept_name }}">
                    </div>
                  </div>


                  <div class="ln_solid"></div>
                  <div class="item form-group">
                    <div class="col-md-6 col-sm-6 offset-md-3">
                      <button class="btn btn-dark" type="reset">Reset</button>
                      <button type="submit" class="btn btn-success">Submit</button>
                    </div>
                  </div>

        </form>

部门管理员

 public function update(Request $request, $id)
{  

   $validatedData = $request->validate([
      'dept_name' => 'required|unique:departments,dept_name,'.$id.',id|max:190'
    ]);
    $department = Department::findOrFail($id);
     $form_data = array(
        'dept_name' =>   $request->dept_name,

    );
     $department->update($form_data);
     return redirect('/departments')->with('success', 'Department is updated successfully ');

}

On submiting the address bar will like

php laravel-5.8
1个回答
0
投票

固定

   <form action="{{ route('departments.update',$department->id) }}"method="POST">
    @csrf
    @method('PUT')
   .......

   </form
© www.soinside.com 2019 - 2024. All rights reserved.