php - Laravel - Redirect from custom class -


how can redirect application specific url custom class?

let's have custom class api in laravel application:

class api {      private function generic_request( $uri )      {        $response = $this->getresponse($uri);        if($response == 'bad_token')         {           //redirect login screen message        }     } 

in 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, can't redirect event listener. right i'm using exceptions feel it's wrong approach. example:

app::abort(401); 

and 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');     } } 

you have create response , return way laravel:

<?php  class api {      public function dowhatever($uri)     {         return $this->generic_request($uri);     }      private function generic_request( $uri )      {        $response = $this->getresponse($uri);         if($response == 'bad_token')         {           return redirect::to('login')->with('message', 'your message');        }      }  }  route::get('test', function() {     return with(new api)->dowhatever('youruri'); }); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -