Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Laravel中获取字符串中的所有列值_Php_Laravel_Laravel 5 - Fatal编程技术网

Php 如何在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',

如何在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','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();