0

I have this function in the laravel controller

public function rawquery()
{ 
     $resultado = DB::statement('SELECT * FROM "w8_w8shipment"');
     dd($resultado);
     return response()->json($resultado);
}

And this is the route to get access to it

Route::get('shipment/rawquery', 'ShipmentController@rawquery');

In the browser and postman, it shows an empty object

{}

And a 200 OK code

I don't know what's wrong. i've already read the docs.

Hiren Gohel
  • 4,942
  • 6
  • 29
  • 48
Gabo Ruiz
  • 536
  • 4
  • 19
  • Possible duplicate of [When to use single quotes, double quotes, and backticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) – aynber Sep 05 '17 at 18:38
  • Ive already check that. I change it like this -> $resultado = DB::statement("SELECT * FROM 'w8_w8shipment' "); and its not working either. @aynber – Gabo Ruiz Sep 05 '17 at 18:41
  • That's because it's still incorrect. Reread the duplicate: column names and table names should be surrounded by backticks, not single or double quotes. `'SELECT * FROM \`w8_w8shipment\`'` – aynber Sep 05 '17 at 18:46
  • I didnt notice that... But I corrected it, and still not working :( Now I have it like this $resultado = DB::statement("SELECT * FROM `w8_w8shipment`"); @aynber – Gabo Ruiz Sep 05 '17 at 18:49
  • Try this instead: `$resultado = DB::table('w8_w8shipment')->get();` If that doesn't work, there's no data in that table. – aynber Sep 05 '17 at 18:50
  • Its weird because its a table with a lot of data and im sure of that. i hope you can help @aynber – Gabo Ruiz Sep 05 '17 at 18:57
  • can you send GET request while `dd` function there ? and see the response ? – Anar Bayramov Sep 06 '17 at 02:00

1 Answers1

0

Try using this function

public function rawQuery()
{
         $data = 'SELECT * FROM "w8_w8shipment"';

         $resultado = DB::select(DB::raw($data));

         return response()->json(['status' => 'success', 'data' => $resultado], '200');
}
Lizesh Shakya
  • 2,482
  • 2
  • 18
  • 42