duan0802 2018-01-21 16:44
浏览 27
已采纳

使用流明从数据库中选择仅虚假数据

I am new to coding, I'm trying to build an API using lumen. Now I have a problem, I cannot find out the solution. here is my code.

$data = Speech::select('select * from speeches where is_requested = 0');
return response()->json(['status'=> 'Success', 'data' => $data], 200);

I went to find out when "is_requested" is false. Now it returns me a blank array. please help me if possible.{of course, it's so easy for you guys... :) }

  • 写回答

1条回答 默认 最新

  • douba3378 2018-01-21 17:52
    关注

    If you are using eloquent ($app->withEloquent();) in your bootstrap/app.php file, you can do it like this :

    <?php
    $data = Speech::where('is_requested', 0)->get();
    return response()->json(['status'=> 'Success', 'data' => $data], 200);
    

    Without eloquent, just use the database connection like this :

    $data = app('db')->select("SELECT * FROM speeches WHERE is_requested = ?", [0]);
    

    Or if the facades are enabled :

    $data = DB::select("SELECT * FROM speeches WHERE is_requested = ?", [0]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路