<commit_before><?php

namespace Zhiyi\Plus\Traits\Model;

use Zhiyi\Plus\Models\User;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

trait UserFollw
{
    /**
     * 正在关注 - 我关注的.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     * @author <NAME> <<EMAIL>>
     */
    public function followings(): BelongsToMany
    {
        return $this
            ->belongsToMany(User::class, 'user_follow', 'user_id', 'target')
            ->withTimestamps();
    }

    /**
     * 关注着 - 关注我的.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     * @author <NAME> <<EMAIL>>
     */
    public function followers(): BelongsToMany
    {
        return $this
            ->belongsToMany(User::class, 'user_follow', 'target', 'user_id')
            ->withTimestamps();
    }

    /**
     * 验证是否关注.
     *
     * @param int|\Zhiyi\Plus\Models\User $user
     * @return bool
     * @author <NAME> <<EMAIL>>
     */
    public function hasFollwing($user): bool
    {
        if ($user instanceof User) {
            $user = $user->id;
        }

        return $this
            ->followings()
            ->where($this->getKeyName(), $user)
            ->value('target') === $user;
    }
}<commit_msg>完成验证是否关注了我方法。<commit_after><?php

namespace Zhiyi\Plus\Traits\Model;

use Zhiyi\Plus\Models\User;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

trait UserFollw
{
    /**
     * 正在关注 - 我关注的.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     * @author <NAME> <<EMAIL>>
     */
    public function followings(): BelongsToMany
    {
        return $this
            ->belongsToMany(User::class, 'user_follow', 'user_id', 'target')
            ->withTimestamps();
    }

    /**
     * 关注着 - 关注我的.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     * @author <NAME> <<EMAIL>>
     */
    public function followers(): BelongsToMany
    {
        return $this
            ->belongsToMany(User::class, 'user_follow', 'target', 'user_id')
            ->withTimestamps();
    }

    /**
     * 验证是否关注.
     *
     * @param int|\Zhiyi\Plus\Models\User $user
     * @return bool
     * @author <NAME> <<EMAIL>>
     */
    public function hasFollwing($user): bool
    {
        if ($user instanceof User) {
            $user = $user->id;
        }

        return $this
            ->followings()
            ->where($this->getKeyName(), $user)
            ->value('target') === $user;
    }

    /**
     * 验证是否关注了我.
     *
     * @param  int|\Zhiyi\Plus\Models\User $user
     * @return bool
     * @author <NAME> <<EMAIL>>
     */
    public function hasFollower($user): bool
    {
        if ($user instanceof User) {
            $user = $user->id;
        }

        return $this
            ->followers()
            ->where($this->getKeyName(), $user)
            ->value('user_id') === $user;
    }
}
{'fraction_non_alphanumeric': 0.1541880341880342, 'fraction_numerical': 0.0, 'mean_word_length': 1.9056603773584906, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4602304', 'n_tokens_mistral': 1006, 'n_tokens_neox': 1012, 'n_words': 168}