I’m trying to redirect to an external URL from a helper class.
Here’s my controller:
JavaScript
x
<?php
namespace AppHttpControllers;
use AppLead;
use IlluminateHttpRequest;
use App;
use Helper;
class MyController extends Controller
{
public function entities_get() {
Helper::my_function(); // <---- Call my Helper class method to redirect.
return view( 'template' );
}
}
Here’s my helper class used in the controller:
JavaScript
<?php
namespace AppHelpers;
class Helper
{
public static function my_function()
{
return redirect()->away( 'https://www.google.com' ); // <---- Not redirecting.
}
}
Why is the redirect() not working inside my_function()? Do I need to include some Laravel classes using the PHP “use” statement?
Advertisement
Answer
You can add send
method and it will work.
JavaScript
<?php
namespace AppHelpers;
class Helper
{
public static function my_function()
{
return redirect()->away('https://www.google.com')->send();
}
}