dynamically sidebar menu but i apply all pages in laravel framework code example
Example: show sidebar dynamically in laravel
if (view()->exists('custom-template')) {
return view('custom-template', $data);
}
return view('default-template', $data);