0

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();
Ketan Harsoda
  • 119
  • 1
  • 11
  • Does this answer your question? [Laravel Eloquent ORM vs Query builder which one better?](https://stackoverflow.com/questions/49105249/laravel-eloquent-orm-vs-query-builder-which-one-better) – N69S Feb 18 '20 at 09:56
  • @N69S I read this article from http://theredfoxfire.github.io/2018-06-10-when-you-need-to-use-laravel-eloquent-or-not.html and here https://inneka.com/programming/laravel/laravel-eloquent-vs-query-builder-why-use-eloquent-to-decrease-performance/ didnt see its referanced to stackoverflow question which is this one https://stackoverflow.com/a/46820024/12232340 you can get more infos there, and its duplicate question so I will remove my answer. –  Feb 18 '20 at 10:17

1 Answers1

2

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.

N69S
  • 16,110
  • 3
  • 22
  • 36