doulan9188 2019-05-16 03:42
浏览 76

如何通过带有laravel框架的php访问数据库?

So I am working on a website with a laravel framework and using postman to test my code, I am writing code in php and am not able to get specific values from the database table in my code.

I've tried variations of select, where and other functions like pluck() and get() yet I keep getting an error. I am unsure on how to put it in an array or get it out of an array.

I've tried:

$passwordResult = DB::table('users')->where('userName', $userName)->get('password')->toArray();
$passwordResult = DB::table('users')->where('userName', $userName)->value('password');
$passwordResult = DB::table('users')->pluck('password');

I want return any value and see it in postman so I can start working on getting specific values. The error I get was that

"Cannot use object of type Illuminate\Database\Query\Builder as array"

  • 写回答

2条回答 默认 最新

  • dongxuan2577 2019-05-16 04:04
    关注

    Please try this may be helpful for you. Because toArray() function is used with collection

     $passwordResult = DB::table('users')->where('userName', $userName)->get('password');
     $passwordResult = $passwordResult->pluck('password')->toArray();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?