You need to give it a key and a value. Example
Session::put('job_id', $request->job_id); //set
$c=Session::get('job_id'); //get
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi I am trying to store job_id (from public function applyforjob )inside session in order to use it in public store function. So I add this line :
use Illuminate\Support\Facades\Session;
then I add inside public function applyforjob session as following:
public function applyforjob(Request $request ,$id)
{
$jobs = Job::find($request->job_id);
Session::put('$request->job_id');
$user = User::find(auth()->user()->id);
$cv = auth()->user()->cv;
$cv=cv::all();
}
This job_id i want to use in following function :
public function store (Request $request ){
if ($cv->save()) {
$application = new JobApplication;
$c=Session::get('$request->job_id');
$application->job_id = $request->job_id;
dd($application);
$user = User::find(auth()->user()->id);
$application->user_id = auth()->user()->id;
$cv = auth()->user()->cv;
$i= $cv->id;
$application->cv_id = $i;
$application->save();
$request->session()->forget('$request->job_id');
return true;
}
Now the the job_id is not recognized in the second function and give me following error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'job_id' cannot be null (SQL: insert into job_applications (job_id, user_id, cv_id, updated_at, created_at) values (?, 3, 145, 2022-03-15 18:19:34, 2022-03-15 18:19:34))
@alya_alsiyabi I am not sure what you are saying. But it sounds like you are misunderstanding how sessions work. You cannot just store a job id by itself. My first example was most likely what you wanted, but i am not sure..
You can look at the session like a hidden input in a form
<input type="hidden" name="job_id" value"{$job_id}" />
Would be somewhat the same as
Session::put('job_id', $job_id);
and getting it out again with input
$request->input('job_id');
and session
Session::get('job_id');
Please or to participate in this conversation.