LoginSignup
1
0

ddRawSql() メソッドでSQLとバインドパラメータを同時に閲覧しよう

Posted at

概要

LaravelでEloquentのクエリを確認する際、多くの方はこう書いてると思います。

$sql = Store::query()->where('name', '東京店')->toSql()
dd($sql);
//"select * from `stores` where `name` = ?" 

実はこれ、バインドパラメータは閲覧できません、別途getBindingsを実行する必要があります。

$parameters = Store::query()->where('name', '東京店')->getBindings()
//array:1 [▼ 
//  0 => "東京店"
//]

しかし、ddRawSqlを使うと!!

Store::query()->where('name', '東京店')->ddRawSql();
//"select * from `stores` where `name` = '東京店'"

SQLとパラメータが同時に見れます

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0