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... :) }

图片转代码服务由CSDN问答提供 功能建议

我是编码的新手,我正在尝试使用流明来构建API。 现在我有一个 问题,我找不到解决方案。 这是我的代码。

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

我去找出“is_requested”为假的时间。 现在它返回一个空白 数组。 请尽可能帮助我。{当然,对你们来说这很容易...... :)}

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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]);
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题