Laravel Eloquent select first 小数点前的字符

Laravel Eloquent select first Characters before the decimal point

我有一个数据库 table,其中有一列包含字符和数字混合的数据。我想要实现的是 select 小数点前的所有字符和数字。以下是数据在列中的情况:

PO995.1
PO995.2
PO995.3
PO995.4

Eloquent查询

 $po_number= DB::table('supplierorders')
                    ->select('supplierorders.*')
                    ->orderby('po_number','asc')
                    ->get();

我只想 select PO995 而忽略 .xx 有没有办法在我的查询中实现这个?

谢谢。

是的,您可以尝试使用 Laravel Collection Map and PHP string explode()

field_name 替换为您 table

中的字段
$po_number= DB::table('supplierorders')
                        ->select('supplierorders.*')
                        ->orderby('po_number','asc')
                        ->get()
                        ->map(function($item)
                        {
                            return explode('.', $item->field_name)[0];
                        });