如何在对象的开头添加记录

问题描述 投票:0回答:1

我读了一个表以建立一个列表框

    $compets = DB::table('compets')->select('id','com_l_compet')
                                  ->where('com_c_st','<>','I')
                                  ->orderby('com_n_ord_aff')
                                  ->get();

我想在列表“所有竞争”的开头添加一个选择。因此选择此选择将重新初始化过滤器。我该怎么做?我使用了数组函数,但是$ compets是一个对象...前置不起作用...我阅读了一些回复和文档,但没有找到简单的解决方案请你能帮忙吗?您知道在哪里可以找到完整的示例,以查看包含过滤器管理+带联接的查询+分页的视图吗?非常感谢

php laravel object record
1个回答
0
投票

您可以将$ compets转换为“ array”,也可以使用“ prepend”函数添加一个开始于集合的项目。

 $compets = DB::table('compets')->select('id','com_l_compet')
                                  ->where('com_c_st','<>','I')
                                  ->orderby('com_n_ord_aff')
                                  ->get()->toArray;
... enter adding item

 $compets = DB::table('compets')->select('id','com_l_compet')
                                  ->where('com_c_st','<>','I')
                                  ->orderby('com_n_ord_aff')
                                  ->get();
... $compets->prepend("All Compets");


© www.soinside.com 2019 - 2024. All rights reserved.