[SOLVED] Passing data from JS to Laravel Controller

Posted 2 years ago by innovation mecom

Hello Community.

I have a system, that works completely in javascript and i want to sent a value to a Controller to my Route. My JavaScript looks like that:

GameManager.prototype.addValueSession = function (value) {
  this.value= value;
  $.ajax({
    type: "POST",
    url: '/session/storeValue',
    data: "",
    success: function() {
      console.log("Value added");
    }
  })
};

and my Controller like that:

public function storeValue(Request $request, $value)
{
      $request->session()->put('value', $value);
}

I don't know how to pass the data and how to write it to the current session. Thank you for your help.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.