How can I redirect application to specific url from my custom class?
Let's say I have my custom class API in Laravel Application:
class API {
private function generic_request( $uri )
{
$response = $this->getResponse($uri);
if($response == 'bad_token')
{
//redirect to login screen with message
}
}
In my controller function:
public function add_employee() {
$data['employee_positions'] = API::generic_request('/employees/position_list');
$this->layout->content = View::make('employees.add_employee')->with($data);
}
I've tried Events
, but you can't redirect from Event
listener. Right now I'm using Exceptions
but I feel like it's wrong approach. For example:
App::abort(401);
and then in global.php
:
App::error(function(Exception $exception, $code)
{
/*CORE API Exceptions*/
if($code == 401)
{
Session::put('message','System Action: Expired Token');
return Redirect::to('login');
}
}