session([key => value])
how to use session in laravel
hello every one. i am new to laravel. i want to store database values in session. but i am not knowing the procedure how to store data in session.please anybody can help me please
Hi ashwinip,
Everything you need to know about using sessions can be found on the Laravel Documentation at https://laravel.com/docs/session
As edoc has said, you can access session data using the Global Session Helper
Retrieve from session store
$keyname = session('keyname');
Put into session store
session(['keyname' => 'value']);
yeah its there in laravel documentation thanks for your reply.
how can i store values related to button in session when i click on button.
Use a form with a hidden input that contains the value you want to store, then in your controller you can store it in the session
but i am inputting any values my code is like this. @foreach($tests as $test)
<div class="col-md-6 book-test-border" >
<div class="book-test-doc" id="book-test-border">
<div class="book-test-inner-box" i>
<div class="row">
<h4 style="margin-left:14px;"><a href="{{ url('/pages/test_description' . $test->id) }}">{{ $test->name}}</a></h4>
<p class="PreTest1">
<div class="col-md-9"><i class="fa fa-info-circle" aria-hidden="true"></i><strong>Pre Test Information:</strong><br><h5 class="book-test-fast">{{$test->test_information}}</h5>
</div>
</p>
<div class="col-md-3 bg-img">
</div>
</div>
<div class="row">
<div class="col-md-8">
<p class="Report1"><i class="fa fa-sticky-note-o" aria-hidden="true"></i><strong>Report TAT:</strong><br><h5 class="book-test-fast">Daily</h5></p>
</div>
<div class="col-md-4">
<h4>Price:${{$test->price}}</h4>
</div>
</div>
<div class="row">
<div class="col-md-7">
<p class="testComp"><i class="fa fa-flask" aria-hidden="true"></i><strong>Components:</strong><br><h5 class="book-test-fast">{{$test->components}} </h5></p>
</div>
<div class="col-md-5">
<a href="{{ url('/pages/cart/' . $test->id) }}"> <button type="button" class="btn btn-default" role="search" data-toggle="modal" id="btn-book-apointment">Book Test</button></a>
</div>
</div>
</div>
</div>
</div>
And what do you want to store in the session ?
onclick of button i have to store testname id and price which i have already fetched from db
Create a button and attach a clickhandler to it, inside the function you fetch the testname id and the price (there are several ways to get these).
Then you submit an ajax request to your endpoint and use the aforementioned values as your payload :)
Please or to participate in this conversation.