vandan
3 months ago
533
6
Laravel

return redirect specific tab not working

Posted 3 months ago by vandan

i m stuck in when i data store then return always active tab so how to set specific tab after return back i m following this tutorial

https://medium.com/@grmcameron/redirect-to-a-specific-tab-in-laravel-149398a9e655

here is my code

<ul class="nav nav-pills nav-pills-sm" role="tablist" id="myTab">
    
    <li class="nav-item active">
                <a class="nav-link" data-toggle="tab" href="#kt_tabs_7_4" role="tab">
                    Profile Details
                </a>
    </li>

    <li class="nav-item">
                <a class="nav-link" data-toggle="tab" href="#kt_tabs_7_5" role="tab">
                        Image
                </a>
        </li>

        <li class="nav-item">
                    <a class="nav-link" data-toggle="tab" href="#kt_tabs_7_1" role="tab">
                        Document
                </a>
        </li>

</ul>

<div class="tab-content">

    <div class="tab-pane active" id="kt_tabs_7_4" role="tabpanel">
        //
    </div>

    <div class="tab-pane" id="kt_tabs_7_5" role="tabpanel">
        //
    </div>

    <div class="tab-pane" id="kt_tabs_7_1" role="tabpanel">
        //
    </div>

</div>

in my controller

public function store(Request $request)
    {
        $id = $request->get('user_id');
        if(request()->has('multiple_doc'))
        {
            $files = Input::file('multiple_doc');
                $picName = str_random(30).'.'.$files->getClientOriginalExtension(); //Insert path in database
            $files->move(public_path().'/PG/Doc/'.$id.'/',$picName);       //Insert image in folder
        }

        $doc = new Document(array(
                'pg_id'=>$request->get('pg_id'),
                'doc_type'=>$request->get('doc_type'),
                'doc_name'=>$request->get('doc_name'),
                'doc_number'=>$request->get('doc_number'),
                'multiple_doc'=>$picName
        ));
        $doc->save();
        notify()->success('PG Document Successfully Added !');
        return back()->withInput(['tab'=>'kt_tabs_7_1']);
    }

in js file

<script>
        //redirect to specific tab
        $(document).ready(function () {
        $('#myTab a[href="#{{ old('tab') }}"]').tab('show')
        });
    </script>

Please sign in or create an account to participate in this conversation.