Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different name fields user table?

I have a form with 2 fields (username, password) and a mysql table with those 2 same fields (username, password), and I authentication system working properly :)

But, I can not make it work if my table fields have different names, for example: (my_user, my_pass).

If you just change the username field on the other also works for me, that gives me problems is the password field.

My config auth.php

'driver' => 'eloquent'

Update

Already found the solution in my controller, the password name can not change.

Before (WRONG): What I've done in first place was wrong

$userdata = array(
        'my_user' => Input::get('my_user'),
        'my_pass' => Input::get('my_pass')
    );

it should be

$userdata = array(
        'my_user' => Input::get('my_user'),
        'password' => Input::get('my_pass')
    );
like image 535
Luck Nilis Avatar asked Jun 20 '13 20:06

Luck Nilis


People also ask

What are the field names in the table?

Field names are the names you give to the columns in a table. The names should indicate what data is contained in each column. For example, when you create a feature class in ArcCatalog, the table is prepopulated with an Object ID field and a shape field.

What is a username field?

The username-field command specifies the value for the name attribute in the login form that identifies the username field. The default value of j_username follows the Java™ Platform, Enterprise Edition standard for login forms.

Can a table have two fields with the same name?

You can't add two columns with the same name to a single table.

How should field names be defined in a database?

A field name should be singular as it should represent a single field characteristic of the subject of the table to which it belongs. A table name, on the other hand, can be plural as this represents a collection of similar objects or events.


2 Answers

You can define you own username and password field in the auth.php inside the config folder.

 return array(
    'driver' => 'eloquent',
    'username' => 'my_user',
    'password' => 'my_pass',
    'model' => 'User',
    'table' => 'users',
 );

I hope this can be of some help.

like image 193
saran banerjee Avatar answered Oct 05 '22 14:10

saran banerjee


I ran into this same problem. You need to extend your model:

// User.php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    protected $fillable = array('name','passwd','email','status','timezone','language','notify');
    protected $hidden = array('passwd');

    protected $table = "users_t";
    protected $primaryKey = "uid";

    public static $rules = array(
        'name' => 'required',
        'passwd' => 'required',
        'email' => 'required'
    );

    public function getAuthIdentifier() {
        return $this->getKey();
    }

    public function getAuthPassword() {
        return $this->passwd;
    }

    public function getReminderEmail() {
        return $this->email;
    }

    public static function validate($data) {
        return Validator::make($data,static::$rules);
    }
}
like image 45
HeyBigE Avatar answered Oct 05 '22 15:10

HeyBigE