I have a project laravel
and I would like to add some values session
when the value of a select input is changed, so I have to do it with javascript
or jquery
what do you recommend, do it with a ajax
in the following way or is there a better or cleaner way?
Route::post('/ajax/add-book', function(){
Session::put( 'bookId', Input::get('bookId') );
});
$('a[data-book]').click(function($e){
$e.preventDefault();
$.post("/ajax/add-book", {
"bookId": $(this).data('book')
});
});
On the other hand, how do I use the session
in one view
? I do a Session::has('param') or a Session::get('param') and it doesn't recognize me session
and if I import the facades it doesn't recognize the has or the get , could someone tell me what I'm doing wrong?
To make the set you already do it right, using
AJAX
and theSession::put
:For the get you are missing. The
route
:And you call it from the function you need: