I need to execute a query with DB::raw
but it seems not working at all.
For some reason, Laravel does not execute the bindings, and the query fails. I have tried a lot of queries, events, and even a simple one doesn't work.
use Illuminate\Support\Facades\DB;
$query = 'select id from :my_table';
$results = DB::select(
DB::raw($query),
[
'my_table' => 'advertisement__rentadvertisements',
]
);
dd($results);
Error
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1 (SQL: select id from :my_table)
Any ideas?