0

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 Answers1

1

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]);
Rafik Tighilt
  • 2,071
  • 1
  • 15
  • 27