How to change value of extra column pivot has integer to string in laravel

Viewed 31

This image for my pivot table:

this is my pivot table

and the code below has for relationship

return $this->belongsToMany(User::class, 'user_team', 'team_id', 'user_id')->withPivot('post');

and in controller im use this code:

$usersTeam = Team::find($id)->users()->get();
return json_encode($usersTeam);

and pic below is response:

this response

Now, im want if post is 0 return in json: "post": "leader" and if 1 return "post": "member"

How should I do this?

Thanks a lot

0 Answers
Related