Support the ongoing development of →
posted 9 years ago
Last updated 2 years ago.

I'd still have an auto increment field in every table, but you can have another field you use as an index.
For example in my users table I have an auto incrementing id field, but I do not use it, I have another index userid.
On a side note, if you have an auto increment primary key field that is named other than id, this line needs to
be placed in model like this:

<?php namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class Powner extends Model implements AuthenticatableContract, CanResetPasswordContract {

	use Authenticatable, CanResetPassword;
    protected $table = 'powners';
    protected $primaryKey = 'ownerid';   //THIS LINE
    protected $fillable = [
        public $timestamps = [];


Why you have an auto_increment field if you don't use it?


Something I was taught that it's always a good idea to have such a field in SQL Server and MySQL.


Sign in to participate in this thread!


Your banner here too?

lovePizza lovepizza Joined 13 Mar 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.