Flarum\Core\Discussion::stateFor PHP Method

stateFor() public method

Get the state model for a user, or instantiate a new one if it does not exist.
public stateFor ( User $user ) : DiscussionState
$user User
return DiscussionState
    public function stateFor(User $user)
    {
        $state = $this->state($user)->first();
        if (!$state) {
            $state = new DiscussionState();
            $state->discussion_id = $this->id;
            $state->user_id = $user->id;
        }
        return $state;
    }