Laravel在Trait内部重定向 [英] Laravel redirect inside of Trait
本文介绍了Laravel在Trait内部重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
trait foo{
public function bar()
{
redirect('/'); //not working
}
}
use Traits;
class DonController extend Controller{
use Traits\foo;
$this->bar();
redirect('/'); //working
}
我是Laravel的新手,我需要在trait内部创建一个重定向方法
I'm new in Laravel, I need to create a redirect method inside of trait
但是我很难在特质中做到这一点.有人知道如何解决这个问题吗?
However I have problem to do it inside of trait. Anyone know how to solve this?
推荐答案
只有控制器方法才能返回重定向对象以转到另一个页面.但是,您可以调用重定向对象的-> send()
方法,以直接从应用程序中的任何位置发送重定向.
Only a controller method can return a redirect object to go to another page. You can however invoke the ->send()
method of a redirect object to send the redirect directly from anywhere in your application.
trait foo {
public function bar()
{
redirect('/')->send();
}
}
这篇关于Laravel在Trait内部重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文