xionghao 的个人博客 / 133 / 1 / 创建于 3年前 / 更新于 3年前
模型层处理后返回,防止外部对象操作修改数据
public function getById($user_id) { return collect((new UserModel)->find($user_id)->toArray()); }
外部集合取值,防止空数据索引异常问题
$user = $userService->getById($user_id); $user_name = $user->get('user_name','');
本作品采用《CC 协议》,转载必须注明作者和本文链接
collect((new UserModel)->find($user_id)->toArray());
从集合转成数组然后又转成集合吗
我要举报该,理由是:
推荐文章: