我试图弄清楚我做错了什么来获取错误信息。我的用户模型有一个status_id字段,它是我的状态表的外键,带有id和name字段。
public function scopeAvailable($query, $current = null)
{
$options = $this->getAvailableOptions($current)->toArray();
return $query->whereIn('name', $options);
}
public function getAvailableOptions(string $current = null)
{
$options = collect(['Active', 'Inactive']);
switch ($current) {
case 'Active':
return $options->merge(['Fired', 'Suspended', 'Retired']);
case 'Injured':
return $options->merge(['Fired', 'Retired']);
case 'Suspended':
return $options->merge(['Suspended', 'Retired']);
}
return $options;
}
public function availableStatuses()
{
$status = $this->status ? $this->status->name : null;
return UserStatus::available($status)->get();
}
类型错误:传递给App \ Models \ UserStatus :: getAvailableOptions()的参数1必须是字符串类型或null,给定对象,在/home/vagrant/projects/app/app/Models/UserStatus.php中调用第45行