php - Laravel - 附加方法抛出异常
问题描述
我得到了以下表格
- 演员
- ID
- 姓名
- 统计数据
- ID
- 姓名
- 演员统计
- 演员 ID
- stat_id
- 数量
我想,给定一个演员,在 actor_stat 中插入一个元素。
控制器中的代码
$actor = Actor::where('name', $actor->name)->first();
$actor->stats()->attach(10); //10 is the id of an existing stat
$actor->save();
演员模型
class Actor extends Model
{
public function stats()
{
return $this->belongsToMany('App\Stat', 'actor_stat')->withPivot('quantity');
}
}
统计模型
class Stat extends Model
{
public function users()
{
return $this->belongsToMany('App\User', 'actor_stat')->withPivot('quantity');
}
}
问题是它抛出异常,我无法读取日志,因为权限被拒绝。建议?
解决方案
发现了问题,我在数据透视表中没有可以为空的属性,所以我必须给它们一个值。
推荐阅读
- linux - 符号链接源文件夹并将文件保存在目标文件夹中
- isabelle - 定义谓词;需要道具=>布尔
- amazon-web-services - Route 53 具有相同域覆盖的两个托管区域
- python - GPS 程序运行 3 个平局然后停止
- android - 如何设置最大高度
- html - 选项卡式导航换行,而不是在移动设备上包装选项卡文本
- python - 在 Nodejs 中预加载 python 库
- ibm-mq - ibm mq 在 solaris 上的日志文件位于何处
- python - 我的函数的数学结果是错误的,我不知道为什么
- flutter - 参数类型 'void Function()?' 不能分配给参数类型 'void Function(String)?'