删除关联数据遇到了问题.
我想删除用户Influencers时同时删除用户关联的数据比如:讨论数据Comment.
尝试过以下的方法但是无效, 没删除Comment数据库里面关联的数据
public static function boot() {
parent::boot();
static::deleting(function($Influencers) { // before delete() method call this
$Influencers->comments()->delete();
$Influencers->comment()->delete();
});
}
laravel 版本:6.0
我的Model 如下
以下是controller:
以下是数据库
我吧InfluencersController.php 的destroy改成了
public function destroy($id)
{
$influencers = Influencers::find($id);
$influencers->delete();
}
提示错误:
"message": "Call to undefined method App\Influencers::comment()",
"exception": "BadMethodCallException",
"file": "/Applications/MAMP/htdocs/zhiyi/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php",
推荐文章: