title: laravel | How to access session array in JavaScript?
body: <p>I am passing an array to a view from my controller.</p>
  
  <p><strong>Here is the controller function:</strong></p>
  
  <pre><code>$notification = array(
              'message' =&gt; 'Welcome Admin!', 
              'alert_type' =&gt; 'success',
          );
  return redirect('/home')-&gt;with('notification', $notification);
  </code></pre>
  
  <p><strong>In my view:</strong></p>
  
  <pre><code>&lt;script&gt;
    @if(Session::has('notification'))//this line works as expected
  
      var type = "{{ Session::get('alert_type', 'info') }}";
     //but the type var gets assigned with default value(info)
      switch(type){
          case 'info':
              toastr.info("{{ Session::get('message') }}");
              break;
  
          case 'warning':
              toastr.warning("{{ Session::get('message') }}");
              break;
  
          case 'success':
              toastr.success("{{ Session::get('message') }}");
              break;
  
          case 'error':
              toastr.error("{{ Session::get('message') }}");
              break;
      }
    @endif
  &lt;/script&gt;
  </code></pre>
  
  <p>as you can see there's clearly something wrong with the way I am trying to access the array value in <code>var type = "{{ Session::get('alert_type', 'info') }}";</code></p>
  
  <p><strong>EDIT- 1</strong> : 
  I tried doing</p>
  
  <pre><code>var type = "{{ Session::get('notification')-&gt;alert_type, 'info' }}";
  switch(type){
      case 'info':
          toastr.info("{{ Session::get('notification')-&gt;message }}");
          break;
  
      case 'warning':
          toastr.warning("{{ Session::get('notification')-&gt;message }}");
          break;
  
      case 'success':
          toastr.success("{{ Session::get('notification')-&gt;message }}");
          break;
  
      case 'error':
          toastr.error("{{ Session::get('notification')-&gt;alert_type }}");
          break;
  }
  </code></pre>
  
  <p>but now I get an error saying</p>
  
  <blockquote>
    <p>Trying to get property of non-object (View: C:\xampp\htdocs\financetest1\resources\views\layouts\master.blade.php) (View: C:\xampp\htdocs\financetest1\resources\views\layouts\master.blade.php)</p>
  </blockquote>
  
  <p>can anyone please help me with this?</p>