为什么在使用带有参数&的route()-> redirect时Laravel方法调用两次代码301? [英] Why Laravel method call twice when using route()->redirect with parameters & code 301?
问题描述
请帮助我,我不知道为什么当我使用命令此命令重定向到新页面时,两次调用Laravel方法:
Please help me, I don't know why Laravel method is called twice times when I use command this command to redirect to new page:
路线:
Route::post('/editor/create/{productCode}', 'EditorController@create')->name('create-new-design');
Route::get('/editor/{designCode}', 'EditorController@edit')->name('edit-design');
EditorController:
public function create($productCode) {
// .. do some thing & redirect to editor page
return redirect()->route('edit-design', ['designCode' => $newDesignCode], 301);
}
public function edit($designCode){
// this method is called twice
$design = Design::where('code', '=', $designCode)->first();
// do extra options --> return editor edit view
return view('editor.edit');
}
流量:
用户通过调用操作[POST]创建新设计的请求:/editor/create/{productCode}->服务器进程&创建设计记录,然后将用户重定向到编辑器页面(->/editor/{designCode}).
Flow:
User request to create new Design by call action [POST]: /editor/create/{productCode} --> Server process & create Design Record then redirect user to editor page ( --> /editor/{designCode} ).
问题:
为什么将用户重定向到编辑页面(或在创建新设计后重新加载此页面)时调用两次 function public function edit($ designCode)?
注释:
我正在使用的这个项目:
Notes:
This project, I'm using:
- Apache服务器
- Laravel 5.8.*
谢谢
推荐答案
尝试一下
return redirect()->route('edit-design', ['designCode' => $newDesignCode]);
无需再次通过301.我相信这可能是原因.或者,您可以共享您的编辑方法.它可能包含导致重复执行的策略/权限查找.
No Need To Pass the 301 again. I believe that might be the cause. Or You can share your edit method. It might contain policies/permission look ups that is causing the double execution.
这篇关于为什么在使用带有参数&的route()-> redirect时Laravel方法调用两次代码301?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!