string - 在字符串错误时调用成员函数 profile()
问题描述
我正在尝试从数据透视表中分离一个字段,但我一直收到错误“调用字符串上的成员函数”作为错误。我正在使用最新版本的 Laravel。
public function removeProfile($child)
{
$profile = Profile::find(1);
$child->profiles()->detach($profile);
return 'Success';
}
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) 调用字符串上的成员函数profile()
解决方案
在你的模型中,一些东西平铺了这个
return $this->belongsToMany('profie')->withPivot('user', 'profile');
并且在您的控制器中应该是
$variable->profile()->where(some condition)->first()->pivot->your_entity
推荐阅读
- python - 如何覆盖 python3 __sub__ 函数以便不更改数据类型
- python - 如何根据它们的 id 从给定的文本文件中提取字符串的第一个、第二个和最后一个实例?
- blazor - Blazor UriHelper.NavigateTo 两次调用页面
- eclipse - 将maven结构映射到Eclipse结构,然后用JDT分析
- openlayers-5 - Openlayers 5 - 如何仅设置 1 个具有不同图标/图像的标记?
- sql-server - .Net Core 2 - 种子数据和通过迁移更新
- mysql - 连接两个表,其中一个表名在另一个表内
- html - 播放新音频时如何使所有其他音频播放器停止?(Angular)
- regex - 替换四位数熊猫
- reactjs - reactjs中如何在Router Link(菜单导航)中传递多个状态