where('username', '=', $this->username)->value('is_online'); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules(): array { return [ 'username' => 'required|exists:users,username', 'password' => 'required|string', 'telephone_id' => 'required|string' ]; } public function after(): array { return [ function (Validator $validator) { $user = User::query()->where('telephone_id', '=', $this->telephone_id); if ($user->exists()) { if ($user->first()->is_online) { $validator->errors()->add( 'telephone_id', __('messages.telephone_id_is_in_use') ); } $user->first()->update(['telephone_id' => null]); } } ]; } }