thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.8k stars 2.67k forks source link

Username column name hardcoded in admin command #5067

Open gekkedev opened 4 years ago

gekkedev commented 4 years ago

Version information

Description

Laravel provides various customization options including a method to specify the name of the field serving as username:

public function username()
{
    return 'email';
}

I changed this field's name to username using the provided method and adjusted the initial user table migration. Voyager works fine when it accesses the email field, but when it works with the name field, SQL errors surface quickly. This affects the voyager:admin command and possibly other functionality as well.
The query being run begins with

insert into `users` (`name`, `email`, `password`, `updated_at`, `created_at`) 

which does not respect the username customization.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Create an empty Laravel project
  2. Change the username column using Laravel's built-in customization feature.
  3. Fully set up Voyager
  4. Try to create an admin using php artisan voyager:admin --create

Expected behavior

The expectation would be to run a query like

insert into `users` (`username`, `email`, `password`, `updated_at`, `created_at`)

Additional context

While heavy customization could break one's neck, the built-in way to change the username field exists for at least 3 major Laravel releases and is documented in several tutorials which makes it worthwhile being supported by Voyager as well.

MrCrayon commented 4 years ago

As the documentation you linked says:

By default, Laravel uses the email field for authentication. If you would like to customize this, you may define a username method on your LoginController:

username is a customization of email not name, it's also done in the Controller so I don't know how we could get that info inside the Command.

Anyway PR are welcome :+1: