Laravel显示错误函数App \ Http \ Controllers \ UserController :: admin_side_update()的参数太少,已传递1个,正好是2个

时间:2019-02-05 18:46:46

标签: php laravel laravel-5 laravel-5.4 laravel-5.6

我执行了除资源以外的其他功能,并且尝试更新数据,并且更新页面显示错误。 我正在解决我试图解决的错误,但是我无法找到传递第二个变量的方法 Error Page Image

Edit.blade.php

    @extends('home')

@section('title', '| Edit User')

@section('dashboard')

<div class='col-lg-4 col-lg-offset-4'>

    <h1><i class='fa fa-user-plus'></i> Edit {{$user->name}}</h1>
    <hr>

     <form action="{{ route('users.updated', ['id' => $user->id]) }}" method="post" enctype="multipart/form-data">
      {{ csrf_field() }}

    <div class="form-group">
        <label for="name" class="col-sm-2 col-form-label">Name *</label>

            <input type="text" class="form-control col-sm-10" id="name" name="name"
             value="{{$user->name}}" />
    </div>


    <div class="form-group">
        <label for="email" class="col-sm-2 col-form-label">Email *</label>

            <input type="email" class="form-control col-sm-10" id="email" name="email"
             value="{{$user->email}}" />
    </div>


    <h5><b>Give Role</b></h5>

    <div class='form-group'>
        @foreach ($roles as $role)
            <input class="form-check-input" type="checkbox" name="roles[]" value="{{ $role->id }}">  
  <label class="form-check-label" for="defaultCheck1">
    {{$role->name}}
  </label>
        @endforeach
    </div>

    <div class="form-group">
       <label for="password" class="col-sm-2 col-form-label">Password *</label>

            <input type="password" class="form-control col-sm-10" id="password" name="password"
            value="{{$user->password}}" />

    </div>

    <div class="form-group row"  style="margin:5%;">

            <button type="submit" class="btn btn-primary col-sm-3 col-sm-offset-3">Edit User</button>
      </div>
  </form>


</div>

@endsection

Web.php

    Route::get('users/{id}/change' ,'UserController@admin_side_edit');
        Route::post('users/savechanges/{id}', [
  'as' => 'users.updated',
  'uses' => 'UserController@admin_side_update'
]);

如果有人请帮助我,这将导致我出错。

更改后after update

1 个答案:

答案 0 :(得分:2)

实际上,您不会将ID传递给刀片中的操作。

要在表单中执行操作,可以使用以下命令:

{{ route('users.updated', ['id' => $user->id]) }}

别忘了在路线中添加参数

Route::post('users/savechanges/{id}', [
  'as' => 'users.updated',
  'uses' => 'UserController@admin_side_update'
]);

希望这可以为您提供帮助。