如何从 blade laravel 调用控制器更新方法?

How to call controller update method from blade laravel?

form method="put" action="{{URL::action('siteController@update')}}" accept-charset="UTF-8"></form>
Route::post('site/update/{id}', 'siteController@update');
 public function update(Request $request, $id)
    {
        //

            $this->validate($request,[
            'Name'          => 'required',
            'Description'   => 'required',
            'Status'        => 'required'           
            ]);
            $Data               = site::find($id);
            $Data->Name         = $request->Name;
            $Data->Description  = $request->Description;
            $Data->Status       = $request->Status;
            if($Data->save())                   
            {
                return $this->index();
            }else{
                return redirect()->back()->withErrors($errors,$this->errorBag());
            }
    }

试试这个,

<form method="post" action="{{ url('site/update/', ['id' => $id]) }}">
@csrf
add your form field here and use button type submit
</form>

通过为您的路线添加名称,例如

Route::post('site/update/{id}', 'siteController@update')->name('site-update');

它允许你在完全不知道的情况下生成它的URL

<form method="post" action="{{ route('site-update', compact('id')) }}">
@csrf
add your form field here and use button type submit
</form>

即使您决定更改 URL,route 助手也不会在意,只要名称保持不变(它只是一个别名)