Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

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 = [
        'ownerid',
        'oname',
        'ostreet',
        'odate',
        'ocheck'
   ];
        public $timestamps = [];
}   

0

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

0

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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

lovePizza lovepizza Joined 13 Mar 2014

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.