'Return to same tab after form submit laravel 8

I have a view with multiple tabs. Each having different forms. When I submit a form from one tab, it returns to same page but primary tab. How could I get to return to same tab from which I was working.

controller

  public function updateProfile(Request $request)
   {

        $user = User::where('id', Auth::user()->id)->first();
        $user->update([
            'full_name' => $request->full_name,
            'phone'     => $request->phone,
        ]);
    }

    return redirect()->back();
 }

html form

<form  action="{{route('management.update')}}" method="POST" enctype="multipart/form- 
data">
      

This is how my tabs are :

      <ul class="nav nav-tabs mb-5" id="ex1" role="tablist">
          <li class="nav-item" role="presentation">
                <a class="nav-link active" id="ex1-tab-2" data-mdb-toggle="tab" href="#ex1- 
                   tabs-2" role="tab"
                aria-controls="ex1-tabs-2" aria-selected="false"><i class='bx bxs-user- 
                 rectangle'></i> User</a>
            </li>
            @endif
            <li class="nav-item" role="presentation">
                <a class="nav-link " id="ex1-tab-1" data-mdb-toggle="tab" href="#ex1-tabs-1" 
                  role="tab"
                    aria-controls="ex1-tabs-1" aria-selected="true"><i class='bx bx- 
                 buildings'></i> Profile</a>
            </li>
        </ul>


Solution 1:[1]

On the controller send the data on which tab should be set active after redirect. You can do it by sending flash session.

Session::flash('active-tab', '#ex1-tab-1'); 

Then on the view end, check if the session exists and make the tab active with the data on session.

@if(Session::has('active-tab'))
@php
    $active_tab= Session::get('active-tab');
@endphp
$(document).ready(function(){
     $(".active").removeClass("active");
     $('{{$active_tab}}').addClass("active");
})

@endif

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shree Sthapit