App\Http\Controllers\UserController::store() 缺少参数 2

Missing argument 2 for App\Http\Controllers\UserController::store()

控制器

  public function store( Request $request,$id)
{
    $new = Car::find($id);

    $new->status = $request ->input('field');
    $new->save();

    redirect('home');
}

查看

@foreach($users as $user)
              @foreach($user->cars as $users)
               {!! Form::open( ['route' => 'user.store', 'method'=>'post','id'=> '$users->id']) !!}
              <th scope="row">1</th>
              <td>{!! Form::label($cars->name)!!}<td>
              <td>{!! Form::label($cars->age)!!}<td>
              <td>{{Form::select($cars->status, ['R' => 'Requested', 'C' => 'Coming', ['name' => 'field']])}} // name is worong but I dont know the alternative 
              <td>{!! Form::submit('Update Profile', ['class' => 'btn btn-primary']) !!}</td>
              {{ Form::close() }}

路线

    Route::Resource('user', 'UserController');

问题

正在尝试保存从 status 中选择的数值到汽车模型中。但我收到有关参数的错误。有人可以告诉我我的错误在哪里吗?我是 Laravel 的新手。

您不能通过这种方式将额外数据传递给 store 操作。

您可以使用php artisan route:list命令查看这条路线。如您所见,它不期望也不传递任何数据。

因此,您需要在隐藏输入中传递 ID:

{!! Form::hidden('userId', $user->id) !!}

并使用 $request->userId

在控制器中获取数据

不要忘记从 store() 中删除 $id 并从 Form::open()

中删除 $users->id

此外,Form::open() 的正确语法(固定拼写错误)是:

{!! Form::open(['method' => 'post', 'route' => 'user.store']) !!}