Laravel:控制器方法执行后如何重定向 [英] Laravel: How to redirect after controller method execution
本文介绍了Laravel:控制器方法执行后如何重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
web.php
:
web.php
:
Route::post('caption/{id}/delete', 'DetailController@deleteCaption');
DetailController.php
:
DetailController.php
:
public function deleteCaption(Request $request, $id) {
$caption = Caption::findOrFail($id);
$caption->delete(); //doesn't delete permanently
return response(204);
}
admin.blade.php
:
admin.blade.php
:
<p value='{{$caption->id}}'>{{$caption->content}}</p>
<form action="caption/{{$caption->id}}/delete" method="post">
<button type="submit">Delete caption</button>
</form>
<form action="caption/{{$caption->id}}/approve" method="post">
<button type="submit">Accept caption</button>
</form>
我要创建该图像,以便在删除图像后将用户重定向回位于localhost:8000/admin的管理页面.
I want to make it so that after I delete an image, the user is redirected back to the admin page, located at localhost:8000/admin.
我该怎么做?我无法理解文档.
How can I do this? Documentation isn't understandable to me.
推荐答案
您可以像这样重定向
public function deleteCaption(Request $request, $id) {
$caption = Caption::findOrFail($id);
$caption->delete(); //doesn't delete permanently
return redirect()->to('link/to/anywhere');
}
或
您可以这样重定向
OR
You can redirect like this
return redirect()->back();
回到您的最后状态.
OR
return route('yourRouteName');
//if there's parameters
return route('yourRouteName', ['id' => 1]);
这篇关于Laravel:控制器方法执行后如何重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文