Ketan Harsoda
Ketan Harsoda

Reputation: 109

Which one will give fast result in laravel eloquent?

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();

Upvotes: 0

Views: 811

Answers (1)

N69S
N69S

Reputation: 17206

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.

Upvotes: 2

Related Questions