表单提交不适用于Laravel

时间:2018-01-21 14:14:45

标签: php forms laravel

我在Laravel中创建了一个html表单但是当我提交时,它没有提交,甚至没有显示任何错误。 这是我的表格:

<form action="{{route('assign.role')}}" method="post">
     {{ csrf_field() }}
     @foreach($users as $user)
       <tr>
        <td>{{$user->name}}</td>
        <td>{{$user->email}} <input type="hidden" name="email" value="{{$user->email}}"></td>
        <!-- <td>{{$user->roles->implode('name', ', ')}}</td> -->
        @foreach($roles as $role)
          <td><input type="checkbox" name="role" {{ $user->roles->contains($role) ? 'checked' : '' }}></td>
        @endforeach
        <td><input type="submit" name=""></td>
       </tr>
     @endforeach 
</form>

这里是路线。

Route::post('/assign',[
  'uses' => 'AppController@assignrole',
  'as' => 'assign.role',
  'middleware'=>'roles',
  'roles'=>['Admin']
]);

和我的控制器方法。

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

1 个答案:

答案 0 :(得分:0)

您无法对一个表单使用多次提交

     @foreach($users as $user)
<form action="{{route('assign.role')}}" method="post">
        {{ csrf_field() }}

    <tr>

        <td>{{$user->name}}</td>
        <td>{{$user->email}} <input type="hidden" name="email" value="{{$user->email}}"></td>
        <!-- <td>{{$user->roles->implode('name', ', ')}}</td> -->
        @foreach($roles as $role)
          <td><input type="checkbox" name="role" {{ $user->roles->contains($role) ? 'checked' : '' }}></td>
        @endforeach


        <td><input type="submit" name=""></td>
    </tr>

</form>
    @endforeach