Law of attraction is a totally speculative concept and has no scientific basis. Although some people believe in this law in the present times, but there is no scientific basis to the law of attraction.
The law of attraction is applicable to the physical world. The proponents of the above idea are applying this physical law to the human world, but this is the drawing of a wrong parallel. It is the same mistake that was committed by Karl Marx. He coined a term "historical determinism", that is, he applied the principle of material determinism to human affairs, which proved to be completely wrong.
Some people believe that whatever happens in life, be it good or bad, is attracted by the person concerned. However, this is wrong thinking. For example, Muslim leaders founded Pakistan in 1947. They deeply believed that Pakistan would emerge as an ideal Islamic state. But this never happened.
You have referred to two verses from the Quran. Whatever hardship befalls you is the result of your own deeds" (42:30), and " No misfortune can affect the earth or your own selves without its first having been recorded in a book, before We bring it into being. (57:22)
These verses have no relation with the philosophy of attraction. You can consult any commentary of the Quran, and you will realize that this reference is incorrect.