Redirect from outside a controller |
(05-14-2020, 11:24 PM)imabot Wrote:(05-12-2020, 06:28 AM)imabot Wrote: Is it possible to redirect from outside a controller (from a library to a given URL for example ?). Without seeing the code (or a example of what you are doing) it's hard to give advice on how to clean it up. You may want to look into doing something like this: PHP Code: return (!$this->checkUser()) ? redirect()->to('not-a-user') : view('user-view', $pageData); Where $this->checkUser() is a private method/function that returns true or false based on your criteria for a user. You can also nest that with something like: PHP Code: return (!$this->checkUserIsLoggedIn()) ? redirect()->to('not-a-user') : (!$this->checkUserRoleIsAdmin()) ? redirect->to('not-an-admin') : view('user-view',$pageData); Where the above code checks if they are even logged in then checks their role with redirects to the appropriate page. and returns the view if everything checks out. |
Messages In This Thread |
Redirect from outside a controller - by imabot - 05-12-2020, 06:28 AM
RE: Redirect from outside a controller - by imabot - 05-14-2020, 11:24 PM
RE: Redirect from outside a controller - by kick - 05-15-2020, 11:11 AM
RE: Redirect from outside a controller - by imabot - 05-18-2020, 02:10 AM
RE: Redirect from outside a controller - by dave friend - 05-18-2020, 08:39 AM
|