Repository navigation
Can Userprovider be optimized? #38231
|
We don't need to "select * from table_ name " every time, especially Auth:: id(), which will greatly affect the database performance. We can add an attribute to the model to get what attributes we need.Besides, can I use model association after Auth:: user()? |
Answered by
DarkGhostHunter
Aug 3, 2021
Replies: 1 comment 1 reply
|
Currently there is no way. The developer expects a You "could" use a Global Scope on the User model, which would be replicated on the The only alternative is to extend the /**
* Get a new query builder for the model instance.
*
* @param \Illuminate\Database\Eloquent\Model|null $model
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function newModelQuery($model = null)
{
$query = is_null($model)
? $this->createModel()->newQuery()
: $model->newQuery();
return $query->select('name', 'email');
} |
1 reply
Answer selected by
wsy998
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently there is no way. The developer expects a
first()equivalent call when dealing with the authenticated user.You "could" use a Global Scope on the User model, which would be replicated on the
UserProvider, but it would affect every query.The only alternative is to extend the
EloquentUserProviderwith your own version, and override thenewModelQuery()method, where the query gets created from a model class name.