在laravel中从mysql数据库检索数据时更改列名

在laravel中从mysql数据库检索数据时更改列名,mysql,sql,laravel,Mysql,Sql,Laravel,我的问题背景: 我的mysql数据库中有一个名为location的空间点字段 我想要实现的目标: DB::table('stores')->select( DB::Raw('ST_X(location)'),DB::Raw('ST_Y(location)')) 我想检索这个空间点 问题是什么: DB::table('stores')->select( DB::Raw('ST_X(location)'),DB::Raw('ST_Y(location)')) 当我检索时,它是:\u0

我的问题背景:

我的mysql数据库中有一个名为location的空间点字段

我想要实现的目标:

DB::table('stores')->select( DB::Raw('ST_X(location)'),DB::Raw('ST_Y(location)'))
我想检索这个空间点

问题是什么:

DB::table('stores')->select( DB::Raw('ST_X(location)'),DB::Raw('ST_Y(location)'))
当我检索时,它是:\u0000\u0000\u0000

我是如何解决的:

DB::table('stores')->select( DB::Raw('ST_X(location)'),DB::Raw('ST_Y(location)'))
好的,现在是什么问题:

DB::table('stores')->select( DB::Raw('ST_X(location)'),DB::Raw('ST_Y(location)'))
字段的检索方式如下:“ST_Y(位置)”:30

好的,现在我想要实现的是:

DB::table('stores')->select( DB::Raw('ST_X(location)'),DB::Raw('ST_Y(location)'))

我想将键名更改为类似“latitude”:30,

您可以在
DB::raw
表达式中使用
as
,它将为其别名

DB::table('stores')
    ->select(DB::Raw('ST_X(location) as longitude'), DB::Raw('ST_Y(location) as latitude'))
    ->get()

您可以在
DB::raw
表达式中使用
as
,它将为其别名

DB::table('stores')
    ->select(DB::Raw('ST_X(location) as longitude'), DB::Raw('ST_Y(location) as latitude'))
    ->get()

感谢它现在解决了,我会在9分钟后接受你的回答,就像stackoverflow对我说的那样:“谢谢它现在解决了,我会在9分钟后接受你的回答,就像stackoverflow对我说的那样:”