laravel - 在运行时在集合上添加属性追加
问题描述
class Student extends Model
{
.... some code here
public function getGroupAttribute()
{
if($this->group == 1)
return 'Group A';
else
return 'No Group';
}
}
我知道有 setAppends() 功能,但该功能仅适用于单个模型。而且我也知道在类中将 $appends 变量定义为的静态方式:
protected $appends = ['group']; // but this is not changable if I did it like this.
如何在控制器的运行时实现 set $append ?
//inside controller
public function getStudent()
{
Student::whereIn('id',[1,4,10,21])->get(); // I want to set the $appends value here
}
解决方案
推荐阅读
- google-chrome-extension - Chrome 扩展连接-src
- c++ - UART 没有接收到 Qt 中所有发送的值
- vbscript - VBScript中使用Split的下标超出范围
- node.js - npm 错误:ENOENT,chmod。这是怎么回事?
- shell - 设置包含多个空格序列的环境变量
- javascript - 如何在反应单选和多选中制作选择框?
- r - 如何在太多循环中加速应用函数
- laravel - 发现“--routePrefix”选项不存在错误
- android - 加载 gif 出现时如何进行模糊活动?
- python - 这行代码如何允许 [end=" "] 在字母之间应用?