Nidecker
Nidecker

Reputation: 190

php - Laravel - string returned as boolean

Model: PlayerResult

protected $fillable = ['result']

result is string (varchar(191)) in db

Saved value in db is 'win' for example, when accessing through eloquent returned as true (boolean).

$var = PlayerResult::where('event_id', $event->id)->whereNotIn('player_id', [$player->id])->first();

In dd($var)'s attributes result is true, in original result is 'win'

I tried casting (in model) but still same...

So why is it returned as boolean? And how to fix it? Thanks

EDIT:

I thought @TimLewis solved the problem, but even I renamed column name to random name, there is still this weird problem. When ->select('result AS exampleVariable') is added to query, result returns true, but exampleVariable returns 'win' - so I thought name of column is problem, but problem is not solved even I renamed that column...

Upvotes: 1

Views: 1127

Answers (1)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111829

Make sure you don't have functions like:

function getResultAttribute

or

function result

also you might be interested to look at

function toArray()

method as it can make some casts before returning array.

If they are not present in your model directly, you should verify any custom traits that are used in your model, because those functions might be defined in those traits.

Upvotes: 1

Related Questions