Laravel : how to maintain different sessions of a same page?

326 views Asked by At

I need to put session on the same page sidebar. when user click on any button session will get for that tab. like

  • Search Job
  • Customers
  • etc

In the sidebar the button or not link with any page. i am creating a dialogue box for each so their is no page for the links that's why i am facing the problem. when user click any of the sidebar button the name should highlight.

DashboardController

 public function disp()
{
    Session::put('page', 'search-job');
    Session::put('page', 'customer');

    return view('front.disp');
}

layout.blade.php

 @if(Session::get('page')=="search-job")
 <?php $active = "active"; ?>
 @else
 <?php $active = ""; ?>
 @endif

 <li class="nav-item {{$active}}">
    <a href="javascript:void(0)" class="nav-link nav-toggle">
       <span class="title">SEARCH JOBS</span>
    </a>
 </li>


 @if(Session::get('page')=="customer")
 <?php $active = "active"; ?>
 @else
 <?php $active = ""; ?>
 @endif

<li class="nav-item {{$active}}">
    <a href="javascript:void(0)" class="nav-link nav-toggle">
       <span class="title">Customer</span>
    </a>
 </li>

How to handle on this sidebar

Thanks!

1

There are 1 answers

2
Babak Asadzadeh On

as i understand from the comments you want to have different active sessions then you have 2 options like below:

  1. put them in different indexes like this:

    Session::put('page-search-job', true);
    Session::put('page-customer', false);  
    

    and in view check them like this:

    <li class="nav-item {{ Session::get('page-search-job') == true ? 'active' : '' }}">
        <a href="javascript:void(0)" class="nav-link nav-toggle">
            <span class="title">SEARCH JOBS</span>
        </a>
    </li> 
    
  2. put it in an array like this:

    Session::put('page', [
        "search-job"=>true,
        "customer"=>false
    ]);
    

    and in view check them like this:

    <li class="nav-item {{ Session::get('page')['search-job'] == true ? 'active' : '' }}">
        <a href="javascript:void(0)" class="nav-link nav-toggle">
            <span class="title">SEARCH JOBS</span>
        </a>
    </li>