使用AJAX保存用户的请求

Project on laravel. I have search input with AJAX in internet shop, which send requests after type any symbol. I need save 5 last full user's requests. requests. I was tried with request->input(), but it isn`t work and i have this result. my function.

public function saveSearchRequest(array $search_elements,Request $request)
{
    if ($request->input('name') == $search_elements['name']) 
    {
        $_SESSION['search_storage'][] = $search_elements['name'];

        return array_unique($_SESSION['search_storage']);
    } else {
        return array_unique($_SESSION['search_storage']);
    }
}

well if you want to save only last five inputs in array maybe you can use php`s array_splice here are the docs

which would modify code like,

public function saveSearchRequest(array $search_elements,Request $request){
  if($request->input('name') == $search_elements['name']){
     $_SESSION['search_storage'][] = $search_elements['name'];

     // this will get you only last 5 elements of array
     $_SESSION['search_storage'][] = array_splice($_SESSION['search_storage'],  -5, sizeof($_SESSION['search_storage']));    

     return array_unique($_SESSION['search_storage']);
 }
 else{
     return array_unique($_SESSION['search_storage']);
 }
}

hope i am also on same line as you are and this is helpful.

You can access an array with all items submitted during the request by calling

$request->all()

To get a singlular input item, use $request->input('key') and replace the 'key' string with your input name e.g query, q