Laravel View Composer duplicating SQL queries for every view bind. How it runs once?

Why does this happen?

The Illuminate\View\View::renderContents() the method is responsible for calling the composer bound to a view, and since any form of view rendering (Blade template inheritance or simple @include statements) executes that method, it means that when any view is rendered any composer bound to it gets triggered.

How to overcome this issue?

Here I share chunks of code for better understanding.