7 months ago

newQuery in User Model

Posted 7 months ago by ycsm

Hi. I am using newQuery in several models without an issue. However, I run into trouble with the user model.

I don't want the newQuery to apply when the user wants to login, as this breaks and the user cant login (however, it appears to work when the user is logged in). Here is what I'm using:


namespace App;

use Carbon\Carbon;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;

class User extends Authenticatable
    use SoftDeletes, Notifiable, HasRoles, HasRelationships;

    public function newQuery()
        $centre_id = session('centre')->id ?? '';
        return parent::newQuery($centre_id)
            ->when($centre_id, function ($query, $centre_id) {
                return $query->where('centre_id', $centre_id);


Is there a way to bypass this newQuery during login?

Please sign in or create an account to participate in this conversation.