[英]Getting an error in Laravel with response()
I am new to PHP and Laravel and I have been working on a tutorial.我是 PHP 和 Laravel 的新手,我一直在编写教程。 I am trying to pass json to a different route but I get an error saying
我正在尝试将 json 传递到不同的路由,但我收到一条错误消息
BadMethodCallException
Call to undefined method Illuminate\Http\RedirectResponse::response()
On my route I have在我的路线上,我有
Route::get('/nuevo','temm@changeView')
->name('tron');
Route::post('/postaedd','temm@fetchAndDis')
->name('postInfoo');
Route::post('/postedd12321',"temm@pazze")
->name('pazze');
On my controller I have在我的控制器上,我有
public function pazze(){
return view('pass');
}
public function fetchAndDis(\Illuminate\Http\Request $request){
$this->validate($request, [
'email' => "required|min:5",
"name" => "required|min:1"
]);
$email = $request->input('email');
$name = $request->input("name");
$info=[
'email' => $email,
"name" => $name
];
return
redirect()
->route('pazze')
->with('info', $info)
->response()
->json($info, 200);
}
After submitting a form thats when I get the error提交表单后,当我收到错误时
I am not sure why you need JSON but you can flash data to the session, then you can check if the session has a variable on the other route.我不确定您为什么需要 JSON,但您可以将数据闪存到会话,然后您可以检查会话是否在另一条路线上有一个变量。 Your
fetchAndDis
method can return redirect with the data flashed to the session:您的
fetchAndDis
方法可以使用fetchAndDis
到会话的数据返回重定向:
return redirect()->route('pazze')->with('info', $info);
Then in pazze
method you can get that flashed session data:然后在
pazze
方法中,您可以获得闪烁的会话数据:
$info = $request->session()->get('info');
Then you can check what to do with or without the session data.然后,您可以检查在使用或不使用会话数据时要做什么。
Laravel 6.x Docs - Responses - Redirects - Redirecting with Flashed Session Data with
Laravel 6.x Docs - Responses - Redirects - Redirecting with Flashed Session Data
with
Laravel 6.x Docs - Sessions - Using the Session - Retrieving Data get
Laravel 6.x Docs - Sessions - Using the Session - Retrieving Data
get
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.