use*_*021 2 postgresql laravel laravel-7
我正在使用 Laravel 7。我有名为“Stores”的表,列“id”是主键和自动增量。
\n当我运行时Store::find(9)->first()它给出错误的结果,当我运行时Store::where('id', 9)->first()给出正确的结果。
我启用了查询日志并得到了关注。
\n为了Store::find(9)->first()
array:2 [\n 0 => array:3 [\n "query" => "select * from "stores" where "stores"."id" = ? limit 1"\n "bindings" => array:1 [\n 0 => 9\n ]\n "time" => 6.41\n ]\n 1 => array:3 [\n "query" => "select * from "stores" limit 1"\n "bindings" => []\n "time" => 0.53\n ]\n]\nRun Code Online (Sandbox Code Playgroud)\n并为Store::where('id', 9)->first()
array:1 [\xe2\x96\xbc\n 0 => array:3 [\xe2\x96\xbc\n "query" => "select * from "stores" where "id" = ? limit 1"\n "bindings" => array:1 [\xe2\x96\xbc\n 0 => 9\n ]\n "time" => 6.89\n ]\n]\nRun Code Online (Sandbox Code Playgroud)\n
小智 5
你不需要打电话first()给find(id)
https://laravel.com/docs/9.x/eloquent#retriving-single-models
//Both results will be the same
Store::find(9);
Store::where('id', 9)->first();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2579 次 |
| 最近记录: |