1

I am using Laravel 5.

I have tried to access the following url

http:://localhost/myproject/public/index.php/tasks

I have added my App/Controllers/Controller.php as following code

public function __construct()
{
    $this->middleware('auth');
}

This code will redirects to login page whenever I try to access any pages in project. That will redirects to the same page which I have tried to access after login. I don't know how laravel doing this. Can anybody tell how this is working?

Praveen Srinivasan
  • 1,562
  • 4
  • 25
  • 52
  • define them on `Route` – jones Jul 08 '15 at 05:41
  • I don't know what you are saying – Praveen Srinivasan Jul 08 '15 at 05:46
  • use something like this `Entrust::routeNeedsRole('your prefix/*', 'your_role', Redirect::to('/'));` – jones Jul 08 '15 at 05:48
  • Shall we talk briefly? – Praveen Srinivasan Jul 08 '15 at 05:54
  • I am using entrust for permission check... I need to check Entrust::can('my pprefix/*', 'my-permission', Redirect::to('auth/login')); This will perfectly redirects to login page... But what I need is after login this must redirect to the page I have entered before For Example... i try to access `http://laravel/project` This will redirect to login page. After login I need to redirect to the same `http://laravel/project'`page if the user has permission. – Praveen Srinivasan Jul 08 '15 at 05:54
  • possible duplicate of [Laravel redirect back to original destination after login](http://stackoverflow.com/questions/15389833/laravel-redirect-back-to-original-destination-after-login) – Pᴇʜ Jul 08 '15 at 06:10
  • Have you tried to implement before/after middleware? – Gaurav Dave Jul 08 '15 at 06:29

1 Answers1

1

Create following function in AuthController. This function will override same function in AuthenticatesAndRegistersUsers trait. Now you can modify its code to redirect to desired location.

/**
 * Get the post register / login redirect path.
 *
 * @return string
 */
public function redirectPath()
{
    if (property_exists($this, 'redirectPath'))
    {
        return $this->redirectPath;
    }

    return property_exists($this, 'redirectTo') ? $this->redirectTo : '/';
}
pinkal vansia
  • 10,240
  • 5
  • 49
  • 62