Laravel SQL returning with interrogation?

Asked

Viewed 91 times

1

I’m making an appointment at Laravel and it is returning the date with the following value.

select `campo` from `tabela` where `campodotipodata` = ?

well it returns so the SQL, follows the code in the LARAVEL

$vardata = date('Y-m-d');
$cardapios = $this->tabela->where('campodotipodata', '=', $vardata)
                ->select('campo')->toSql();//get();
  • 2

    It’s just like that in the place of that ? it will put the date at the time you call the get(), for example, but tell me what the doubt is?

  • it returns nothing despite having data in the database.. toSql is because it was testing

  • Also, as this recorded that date?

1 answer

2

Yes really, the uses Preparedstatements, this means that the value is replaced by the positioning (placeholders) and following an order that is established in the development.

If by chance you want to know the data sent and the SQL generated do the following:

$vardata = date('Y-m-d');
$builder = $this->tabela->where('campodotipodata', '=', $vardata)->select('campo');

SQL generated:

var_dump($builder->toSql());

Values and their orders, which are or will be replaced(s) in the space(s) reserved(s):

var_dump($builder->getBindings());

References

Browser other questions tagged

You are not signed in. Login or sign up in order to post.