#Laravel's smarts getting attribute as integer not string

7 messages · Page 1 of 1 (latest)

viscid garnet
#

I have a model with a property called job. This property is a string of integers which is correct. I have a relationship that links an active job to a job record but Laravel casts job as an integer but it needs to be an string instead. I have tried adding the $casts attribute to the both models but it still casts it as a integer.

Anyone know how to fix this?

zealous rune
#

It looks like from your screenshot it is being cast as a string.

viscid garnet
#

The column in SF_JOB is varchar as well

zealous rune
#

Your error reads like it is trying to convert a varchar into an int column in the DB. What is the job column for the job_active table?

mental nacelle
#

I think you need to override getKeyType() on the model

Relation.php

return $model->getKeyName() === last(explode('.', $key))
  && in_array($model->getKeyType(), ['int', 'integer'])
    ? 'whereIntegerInRaw'
    : 'whereIn';