Laravel constructor redirect is not working
Make Sure to use Illuminate\Routing\Redirector; and pass it to the constructor. (Laravel 5.2)
use Illuminate\Routing\Redirector;
class ServiceController extends Controller {
public function __construct(Request $request, Redirector $redirect) {
$this->service = Auth::user()->Service()->find($request->id);
if (!$this->service) {
$redirect->to('/')->send();
}
}
Returning a Redirect
to execute it is only possible from routes, controller actions and filters. Otherwise you have to call send()
Redirect::to('login')->send();
However you should really use a filter for this