Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 函数模型::destroy()中的参数太少_Php_Laravel_Laravel Routing_Laravel 8 - Fatal编程技术网

Php 函数模型::destroy()中的参数太少

Php 函数模型::destroy()中的参数太少,php,laravel,laravel-routing,laravel-8,Php,Laravel,Laravel Routing,Laravel 8,我正在Laravel 8.6.0中设置删除路由,如下所示: api.php Route::delete('code-rule/{id}', 'api\v1\CodeRuleController@destroy'); coderRuleController.php /** * Remove the specified resource from storage. * * @param \App\Models\CodeRule $codeRule

我正在Laravel 8.6.0中设置删除路由,如下所示:

api.php

Route::delete('code-rule/{id}', 'api\v1\CodeRuleController@destroy');
coderRuleController.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());
    }
现在,当我尝试在postman中向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
我不知道为什么会发生这种情况,当我用谷歌搜索时,我只会让人们想传递更多的参数,而不是我面临的问题。

方法接受参数
destroy($primaryKey)
,以删除模型实例,如:

CodeRule::destroy(1);
CodeRule::destroy(1, 2, 3);
您可以这样使用
destroy()
方法:

CodeRule::destroy($id);
或者您可以使用方法:

CodeRule::where('id', $id)->first()->delete();

destroy()
方法分别加载每个模型,并对其调用
delete()
方法,以便触发
deleting
deleted
事件。

我认为,如果将
destroy()
更改为
delete()
@sta谢谢,这是有效的。