Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lewisbhs's avatar

How can I change Laravel Sparks Authentication System?

Hi,

Can you please let me know, how I can modify Laravel Spark's login system to check if company_name == config('global.company_name') (In a standard auth query it would just be

AND WHERE company_name = "' .  config('global.company_name') . '"

Can you also please tell me how I could change the email part of the authentication, to username(column name = 'name')

Thank you in advance.

0 likes
4 replies
lewisbhs's avatar

I am still looking for a solution for the AND WHERE company_name = '' part of it, I have decided to change my plans and get rid of the username part of it so the username part of my request no longer required.

Hopefully someone can help me figure this out. Thanks in advance.

christopher's avatar

Just edit your AuthController`s login method:

https://github.com/laravel/spark/blob/1.0/src/Http/Controllers/Auth/LoginController.php#L57

So you would change this line

$user = Spark::user()->where('email', $request->email)->first();

to something like this

$user = Spark::user()->where('company_name', $request->company_name)->first();

And change the email <input> to your company_name field in the views/auth/login.blade.php

So change this

<input type="email" class="form-control" name="email" value="{{ old('email') }}" autofocus>

to this

<input type="text" class="form-control" name="company_name" value="{{ old('company_name') }}" autofocus>
lewisbhs's avatar

@christopher I still need emails, also company name needs to check config('global.company_name');

So would this work?

$user = Spark::user()->where('email', $request->email)->where('company_name', config('global.company_name')->first();

Thank you.

lewisbhs's avatar

@Christopher I just gone to apply this to my project, that is not there. The following is there:

    public function login(Request $request)
    {
        if ($request->has('remember')) {
            $request->session()->put('spark:auth-remember', $request->remember);

            $request->merge(['remember' => '']);
        }

        return $this->traitLogin($request);
    }

Please or to participate in this conversation.