Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.2 auth change 'id' to 'customer_id'

In this topic I asked a question: Laravel 5.2 auth change 'users' table

But now my problem has changed. By default the users table has an id. But I want a customer_id, so I changed everything but it don't work. It keeps asking for an id.

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select * from klanten where id = 1 limit 1)

In the table klanten I have a customer_id, but it keeps asking for an id.

Things I've changed:

config/auth

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
        'table' => 'klanten',
    ],

created a klanten migration

public function up()
{
    Schema::create('klanten', function (Blueprint $table) {
        $table->increments('klant_id');
        $table->string('voornaam');
        $table->string('email')->unique();
        $table->string('password', 64);
        $table->rememberToken();
        $table->boolean('status');
        $table->timestamps();
    });
}

If I remove timestamps it keeps asking for created_at and updated_at too.

Controllers/Auth/AuthController

protected function validator(array $data)
{
    return Validator::make($data, [
        'voornaam' => 'required|max:255',
        'email' => 'required|email|max:255|unique:klanten',
        'password' => 'required|confirmed|min:6',
    ]);
}

protected function create(array $data)
{
    return User::create([
        'voornaam' => $data['voornaam'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    ]);
}

app/User

protected $table = 'klanten';

protected $fillable = [
    'voornaam', 'email', 'password',
];

I hope somebody can help me!

like image 643
Draity Avatar asked Jan 08 '16 09:01

Draity


People also ask

How can I get Laravel 8 Controller ID?

$id = Auth::id(); // Retrieve the currently authenticated user's ID... $user = $request->user(); // returns an instance of the authenticated user... $id = $request->user()->id; // Retrieve the currently authenticated user's ID... $user = auth()->user(); // Retrieve the currently authenticated user...


1 Answers

edit your user model and add this:

protected $primaryKey = 'customer_id';
like image 194
ssuhat Avatar answered Sep 30 '22 04:09

ssuhat