1

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...

15
  • "[...] when accessing through eloquent" Can you post you Eloquent code? Might be easier for us to recreate this issue seeing your actual code. Commented Nov 20, 2017 at 15:21
  • @TimLewis - $var = PlayerResult::where('event_id', $event->id)->whereNotIn('player_id', [$player->id])->first(); Commented Nov 20, 2017 at 15:31
  • 1
    @TimLewis - edited Commented Nov 20, 2017 at 15:38
  • 1
    I wonder if ->result is a reserved word in Eloquent. If you add a ->select("result AS exampleVariable") to your query then do a dd($var->exampleVariable); does it still return true? Commented Nov 20, 2017 at 15:56
  • 1
    Already changed column name, thanks a lot @TimLewis Commented Nov 20, 2017 at 17:35

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.