有没有针对单条数据处理的类似于 map() 的方法?

andyzu
$data = Db::table('contentinfo')
            ->select('id', 'classesinfo_id', 'title', 'content', 'author')
            ->where("classesinfo_id", '=', $param['classesinfo_id'])
            ->where("status", '=', 1)
            ->whereNull('deleted_at')
            ->get()
            ->map(function ($res) {
                $res->classesinfo_id_name = Db::table('classesinfo')
                    ->where('id', '=', $res->id)
                    ->value('title');
                $res->author_name = Db::table('admin_users')
                    ->where('id', '=', $res->id)
                    ->value('username');
                return $res;
            });

如果我把 get() 换成 first() 后,map() 方法不能用了,有没有针对单条数据处理的类似于 map() 的方法?

280 1 0
1个回答

belifforz

模型关联呗

  • 暂无评论
🔝