📜  在条件 laravel 上向数组添加字段 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:39.980000             🧑  作者: Mango

代码示例1
return [
        'id' => $this->id,
        'name' => $this->name,
        'email' => $this->email,
        $this->mergeWhen(Auth::user()->isAdmin(), [
            'first-secret' => 'value',
            'second-secret' => 'value',
        ]),
        'created_at' => $this->created_at,
        'updated_at' => $this->updated_at,
    ];