简体   繁体   中英

Laravel eloquent HasMany type error at include in controller

["

I have a Customer model with many Loans records related by idecli<\/code> Varchar field in both tables.<\/i>

class Customer extends Model
{
    use HasFactory;

    protected $table = 'tblcli';
    protected $primaryKey = 'idecli';

    public function loans() {
        return $this->hasMany(Loan::class,'idecli','idecli');
    }

Laravel eloquent assumes that the primary key is numeric , since it is necessary to inform the model that the key is type string type. Works fine!

class Customer extends Model
{
    use HasFactory;
    use EloquentJoin;

    protected $table = 'tblcli';
    protected $primaryKey = 'idecli';
    protected $keyType = 'string';
...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM