猿问

如何在 Laravel 中获取字符串中的所有列值

如何在 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


请帮助提前谢谢


慕的地6264312
浏览 240回答 3
3回答

慕仙森

你可以像这样转换 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 CAST函数转换为无符号整数$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();

幕布斯6054654

您可以在 mysql 查询中将整数转换为字符串,如下所示:.. ->selectRaw('CAST(id as CHAR(50)) as app_user_id', 'name', ...) ->first();
随时随地看视频慕课网APP
我要回答