Laravel重定向Trait内部
问题描述:
trait foo{
public function bar()
{
redirect('/'); //not working
}
}
use Traits;
class DonController extend Controller{
use Traits\foo;
$this->bar();
redirect('/'); //working
}
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?
trait foo {
公共功能栏()
\ {
“); //不工作
}
}
use Traits;
class DonController扩展控制器{
使用Traits \ foo;
$ this-> bar();
redirect('/ “); // working
}
code> pre>
我是Laravel的新手,我需要在trait中创建一个重定向方法 p>
但是我在特质内有问题。 任何人都知道如何解决这个问题? p>
div>
答
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();
}
}