I've observed that many PIs are especially prone to having favorite students in their research group, and will treat these students differently than others. Most of the time, this isn't so obvious and doesn't cause problems. However, from time to time, this will be made extremely clear as the time spent on the "favorites" are orders of magnitude more than other students in the lab. This also includes assignments of better projects etc. Of course, I realize that as humans, everyone has favorites, and it is unrealistic to expect manager figures to treat everyone equally. However, I have noticed that in the few groups I've worked in, some PIs will make it embarrassingly clear. For instance, it will often lead to hurt feelings and lost productivity when something essential is not done for one student's project (i.e. read over drafts, provide necessary components of experiments) while the advisor runs to help another student with mundane aspects of their experiment (i.e. actually helping them do the experiments, or spending a lot of time talking with them while telling others they are busy). This is of course common in all workplaces, but I do feel that the advisor/trainee relationship is different in that in many ways the success of the student is very much dependent on the advisor.
An anecdote: my advisor was extremely hands-off for me; we met pretty infrequently and when we met, it was mostly spent on talking about small side issues that came up in my projects. Another student of my advisor had a very different experience. He met extensively with my advisor, he found projects for him to work on (I proposed my own, and my advisor didn't know much of my project until I wrote my thesis). The tension for me reached its climax when my defense date drew near; he told me that he was busy with the other student's thesis and that he will sign mine after he is finished with editing the other student's thesis. He ended up reading my thesis only a couple of days before my defense.
Although this seemed like favoritism, in the end it wasn't. He must have judged me to be an independent and competent researcher, because I got more and better job offers afterwards.
So, there really isn't anything you can do. You should just focus on your own projects, and hopefully your advisor is there when you really can't solve the problem on your own. But if you treat each time that your advisor isn't there as an opportunity to show your competence (whether you think your advisor noticed it or not... it does accumulate!) you'll walk out having become independent, which is an important quality to possess in academia.
Your description reminds me of siblings' experiences of sibling rivalry in families.
Different people need different things. Different people need different amounts of things. Keeping this in mind can help prevent hurt feelings and resentments.
I suggest you focus on what you can do to make things better for you and for your group. Here are a couple of ways that might be done. These might not all be a good fit for you and your group -- I am just brainstorming. But I'd like you to do some brainstorming about this too.
Make an objective assessment of what you need help with and what you're able to do without help.
Assert yourself to get the help you need.
Make yourself available to help others in your group.
And don't forget to make plans for how you will do things better when you are a PI.
Personal effort to win the teacher's attention may not be what you want to attempt. The nature of your teacher's favoriticism sounds detrimental. A good teacher should know the difference between explaining things to a student and teaching the student how to decipher the meaning of things by themselves. You can't fix this part of your teacher. However, certain acts of the teacher (as described by you) are unjust and something needs to be done about it.
Anything you do in this regard has to be group effort. A hostile or challenging attitude migh do more harm. Maybe the best people who can approach the teacher regarding this issue in a non-hostile manner will be the favorite students themselves.
It all depends on What kind of a person the favorite student is. I used to be a favorite student in most classes, but I never reserved any private time with any teacher. When the other students had any issue with the teacher focussing too much on me, they used to express their disapproval directly to me. .