I don't quite understand if your problem is in the backend side (laravel) or in the frontend side (javascript).
If you want to access an inner key from an array stored in a session you can use the dot-notation:
// app/Http/routes.php
$router->get( '/test', function ( ) {
$incidentData = ['incidentID' => 1, 'incidentReference' => 'ref'];
\Session::set('incidentData', $incidentData); // use set() not push()
return \Session::get('incidentData.incidentID'); // will return 1
} );
If you return \Session::get('incidentData'); Laravel will send a JSON object as the value is an associative array. So in this case:
// app/Http/routes.php
$router->get( '/test', function ( ) {
$incidentData = ['incidentID' => 1, 'incidentReference' => 'ref'];
\Session::set('incidentData', $incidentData);
return \Session::get('incidentData'); // will return { "incidentID" : 1, "incidentReference" : "ref" }
} );
and in your view
<script>
$(function () {
'use strict';
// using jquery for simplicity
$.get('./test' ).success( function ( incidentData ) {
alert( incidentData ); // will alert [object Object]
alert( incidentData.incidentID ); // will alert 1
} );
});
</script>