0

I have just set up my Laravel installation and I have been reading the documentation and it appears that it ships with a authentication system built in. Which I would like to use rather than build my own ( which I have done in the previous version)

My question is I would like to change the default routes and the structure to something like:

www.example.com/register and www.example.com/login

At the moment it uses an auth folder so www.example.com/auth/register and www.example.com/auth/login

I just think that my way is cleaner and more user friendly. I would also like to change the forgot password to www.example.com/forgot-password

I have tried various examples and even new routes etc but I keep getting a not found exception. It is just bugging me as I would like to keep what is already there but alter it slightly as they say dont fix what is not broken.

Hopefully someone can point me in the right direction.

1
  • You can use loginPath property in your AuthController to alter it Commented May 8, 2015 at 8:41

2 Answers 2

2

By default the default auth routes use Route::controllers(['auth' => 'Auth\AuthController']), the Route::controller() method generates the routes based upon the functions available on the controller.

You should be able to remove this line and create your own routes for them. If you look at the Illuminate/Foundation/Auth/AuthenticatesAndRegistersUsers trait you can see the functions available. Simply map your routes to those functions available on your auth controller.

Heres a couple to get your started

Route::get('/register', ['uses' => 'Auth\AuthController@getRegister']);
Route::post('/register', ['uses' => 'Auth\AuthController@postRegister']);

Route::get('/login', ['uses' => 'Auth\AuthController@getLogin']);
Route::post('/login', ['uses' => 'Auth\AuthController@postLogin']);
Sign up to request clarification or add additional context in comments.

3 Comments

So I now have [link]www.example.com/register [/link] and [link]www.example.com/login[/link] The form work brilliantly, however when I click register is give me a not found expetion to [link]www.example.com/auth/register[/link] and [link]www.example.com/auth/login[/link] Now I have left the file structure the same way it was shipped with Laravel. But I keep getting the http error, and also the forgot password is the same and I have not changed that.
You'll need to update the urls in each of the forms found in your auth views so they post to the correct URL.
"These are known as RESTful controllers" what? That is really wrong statement... see wiki why. What you meant is this instead.
0

You can set $loginPath property in AuthController

These are some other properties you may also need

  1. Where user is redirected after logout
    $redirectAfterLogout

  2. The post register / login redirect path
    $redirectPath

  3. Path to the login route.
    $loginPath



class AuthController extends Controller {

        protected $loginPath = 'login';  //example.com/login

        use AuthenticatesAndRegistersUsers;

        public function __construct(Guard $auth, Registrar $registrar)
        {
            $this->auth = $auth;
            $this->registrar = $registrar;
            $this->middleware('guest', ['except' => 'getLogout']);
        }

    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.