Php 如何在Laravel中获取字符串中的所有列值
如何在laravel查询中获取字符串中的所有列值, 我的问题是Php 如何在Laravel中获取字符串中的所有列值,php,laravel,laravel-5,Php,Laravel,Laravel 5,如何在laravel查询中获取字符串中的所有列值, 我的问题是 $profile = DB::table('app_user')->where([ 'email' => $request->email, 'password' => md5($request->password), 'app_id' => $request->app_id ])->select('id as app_user_id','id',
$profile = DB::table('app_user')->where([
'email' => $request->email,
'password' => md5($request->password),
'app_id' => $request->app_id
])->select('id as app_user_id','id','name','email','user_image','activate')
->first();
这个返回对象
"app_user_id": 2857687,
"id": 2857687,
"name": "zahid"
我想这样输出
"app_user_id": "2857687",
"id": "2857687",
"name": "zahid"
我使用的是laravel 5.4
请提前感谢您的帮助您可以像这样投射MySQL数据
$profile = DB::table('app_user')->where([
'email' => $request->email,
'password' => md5($request->password),
'app_id' => $request->app_id
])->select(DB::raw('CAST(id AS varchar) as app_user_id, CAST(id as varchar) as id, name, email, user_image, activate'))
->first()
您可以在mysql查询中将整数转换为字符串,如下所示:
。。
->选择raw('CAST(id作为CHAR(50))作为app\u user\u id','name',…)
->第一个()代码>使用mysql函数转换为无符号整数
谢谢你的回复@Shahadat Hossain我们可以使用任何其他方法获取字符串中的所有字段,因为我有更多的数据要转换为字符串,正如我从MySQL casting中了解到的,这是最好的选择。你可以阅读这篇文章@Zain说真的,我不喜欢在MySQL中转换数据。如果您在web前端使用此日期,那么我建议使用js在前端转换数据。它将保持简单,看起来很棒。
$profile = DB::table('app_user')->where([
'email' => $request->email,
'password' => md5($request->password),
'app_id' => $request->app_id
])->select(\DB::raw('CAST(id AS UNSIGNED) as app_user_id'),\DB::raw('CAST(id AS UNSIGNED) as id'),'name','email','user_image','activate')
->first();