简体   繁体   English

Laravel:如何在同一控制器中将变量从一个函数传递给来自Ajax调用的另一个函数

[英]Laravel : how to pass variable from one function to other coming from ajax call in same controller

I am new to laravel facing issue to pass variable from one function to another function i want to pass getidvalue variable from questionquiz5 to previousbtn function?? 我是laravel的新手,面临将变量从一个函数传递到另一个函数的问题,我想将getidvalue变量从questionquiz5传递给previousbtn函数? here is my code 这是我的代码

public  function questionquiz5(Request $request){
  static $startscore=0;
  static $getscore;
  static $level;
  $var = "hi";

  $getidvalue = Input::get('getid');
  $getanswervalue = Input::get('getanswer');



  $dbscore = \DB::table('5question')->select('question_id','correct_answer','question_marks','question_level')->where('question_id','=',$getidvalue)->get();

  //// some code...........


  Session::push('getscoresession',$getscore);
  Session::push('level',$level);


  $getsession = [  'qid' => $getidvalue,  'answer' => $getanswervalue];

  Session::push('answer', $getsession);

  return response()->json(['qid'=>$getidvalue,'answer'=>$getanswervalue]);   

  return $this->previousbtn( $getidvalue);
  return $this->previousbtn( $getanswervalue);
}     


**previousbtn function:**


public function previousbtn(Request $request, $getidvalue)
{
  $prevbtnvalue = Input::get('page');  
  $getcompid = $this->getidvalue;
  echo "$getcompid";     
}

the error: 错误:

getting error : Type error: Too few arguments to function App\\Http\\Controllers\\scorecontroller::previousbtn(), 1 passed and exactly 2 expected 出现错误:类型错误:函数App \\ Http \\ Controllers \\ scorecontroller :: previousbtn()的参数太少,已传递1个,正好是2个

Like the error indicates, you are passing too few arugments. 像错误所指示的那样,您传递的麻将太少。

return $this->previousbtn( $getidvalue);

Should be 应该

return $this->previousbtn($request, $getidvalue);

Or if the request object is not used in the previousbtn method you can remove it from the arguments. 或者,如果previousbtn方法未使用请求对象,则可以将其从参数中删除。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在laravel控制器中如何将变量从一个函数传递到另一函数 - in laravel controller how to pass variable from one function to other function 将参数从一个函数传递到同一控制器 Laravel 中的另一个函数 - Pass parameter from one function to other function in the same Controller Laravel 如何在 Laravel 应用程序中从同一 controller 调用其他 function? - How to call other function from the same controller in Laravel application? 我想在同一控制器的不同函数中传递变量-Laravel - I want to pass variable in different function from same controller - Laravel 如何在Laravel中将变量从一个控制器传递到另一个控制器 - How to pass variable from one controller to another controller in laravel 将变量从一个函数传递到同一控制器中的另一个函数(laravel 5) - Passing variable from one function to another function in same controller (laravel 5) Laravel将变量从控制器中的1个函数传递给另一个函数 - Laravel pass variable from 1 function in controller to another one Laravel Controller-在函数之间传递变量 - Laravel Controller - Pass a variable from function to function 如何将变量数组从laravel控制器传递给我的Ajax函数 - How to pass an array of variables from a laravel controller to my ajax function 需要将具有相同值的变量从一个 function 传递到另一个 laravel - Need to pass the variable with same value from one function to another in laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM