Laravel 函数中的参数太少 Model::destroy()
Laravel Too few arguments in function Model::destroy()
我正在 Laravel 8.6.0 中设置删除路由,如下所示:
api.php
Route::delete('code-rule/{id}', 'api\v1\CodeRuleController@destroy');
CodeRuleController.php
/**
* Remove the specified resource from storage.
*
* @param \App\Models\CodeRule $codeRule
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
return response()->json(CodeRule::where('id', $id)->first()->destroy());
}
现在,当我尝试在邮递员中向 url localhost:8080/api/v1/code-rule/13/
发送 delete
请求时,我得到以下响应:
ArgumentCountError: Too few arguments to function Illuminate\Database\Eloquent\Model::destroy(),
0 passed in C:\Ontwikkeling\TenT en Batchcontrol\API\app\Http\Controllers\api\v1\CodeRuleController.php
on line 112 and exactly 1 expected in file
C:\Ontwikkeling\TenT en Batchcontrol\API\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php
on line 905
我不知道为什么会这样,当我 google 这样做时,我只会让人们想要传递更多的论点,而不是我面临的问题。
我正在 Laravel 8.6.0 中设置删除路由,如下所示:
api.php
Route::delete('code-rule/{id}', 'api\v1\CodeRuleController@destroy');
CodeRuleController.php
/**
* Remove the specified resource from storage.
*
* @param \App\Models\CodeRule $codeRule
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
return response()->json(CodeRule::where('id', $id)->first()->destroy());
}
现在,当我尝试在邮递员中向 url localhost:8080/api/v1/code-rule/13/
发送 delete
请求时,我得到以下响应:
ArgumentCountError: Too few arguments to function Illuminate\Database\Eloquent\Model::destroy(),
0 passed in C:\Ontwikkeling\TenT en Batchcontrol\API\app\Http\Controllers\api\v1\CodeRuleController.php
on line 112 and exactly 1 expected in file
C:\Ontwikkeling\TenT en Batchcontrol\API\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php
on line 905
我不知道为什么会这样,当我 google 这样做时,我只会让人们想要传递更多的论点,而不是我面临的问题。