Home » Php » php – Which one will give fast result in laravel eloquent?

php – Which one will give fast result in laravel eloquent?

Posted by: admin February 25, 2020 Leave a comment

Questions:

Which eloquent statement will give a fast result?

$getData = User::selectRaw('user_name')->where('user_id',1)->first();

$getData = User::where('user_id',1)->first();
How to&Answers:

In this case, the difference on performance is negligible. To make the query faster, you need the field user_id to be indexed in your database.