TheUnreal
TheUnreal

Reputation: 24472

Laravel - Adding information to relationship output

Hopefully you can help me, Thanks!

Upvotes: 1

Views: 56

Answers (1)

Samsquanch
Samsquanch

Reputation: 9146

Here's how I would do it:

In your Pet model add a requiredexp function:

function requiredexp() {
    return DB::table('pet_exp')->where('level', $this->level)->value('requiredExp');
}

This should return the requiredExp for the level of the pet that you call the function on (i.e. $pet->requiredexp)

EDIT:

You can also do it as an attribute:

function getRequiredexpAttribute($value) {
    return DB::table('pet_exp')->where('level', $this->level)->value('requiredExp');
}

Upvotes: 1

Related Questions