katie hudson
katie hudson

Reputation: 2893

Laravel 5 authentication on home page

I have tried authentication before, but it has always been with views in my auth folder. I am now doing something different and cant seem to get it working. So I have this route which displays my homepage

Route::get('/', function () {
    return view('index');
});

On my homepage, I have my register and login forms. I wont show everything, but my register form looks like the following

<form class="form-horizontal" role="form" method="POST" action="/">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    <div class="form-group">
        <div class="col-md-12">
            <input type="text" class="form-control" name="first_name" value="{{ old('first_name') }}" placeholder="First Name">
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-12">
            <input type="text" class="form-control" name="last_name" value="{{ old('last_name') }}" placeholder="Last Name">
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-12">
            <input type="email" class="form-control" name="email" value="{{ old('email') }}" placeholder="Email">
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-12">
            <input type="password" class="form-control" name="password" placeholder="Password">
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-12">
            <input type="password" class="form-control" name="password_confirmation" placeholder="Confirm Password">
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-12">
            <button type="submit" class="btn btn-primary">
                Register
            </button>
        </div>
    </div>
</form>

I then tried adding my routes for the registration

Route::get('/register', 'Auth\AuthController@getRegister');
Route::post('/register', 'Auth\AuthController@postRegister');

Because this is using the built in authentication, looking at the Traits, things like getRegister return a view in the auth folder. So in my AuthController, I have added

 public function getRegister()
 {
     return view('/');
 }

However, if I try to register, I still get a MethodNotAllowedHttpException.

What would be the stages I need to go through in order to get registration and login onto my homepage?

Thanks

Upvotes: 1

Views: 27

Answers (1)

JuanDMeGon
JuanDMeGon

Reputation: 1211

Be careful with the action of your form. You action is "/" but you registered the route Route::post('/register'....

So, your action for the form must be: action="/register"

It is going to make the request in the right rout.

Hope it helps.

PS: Check this course: Learn Laravel. There are explained step-by-step some concepts like this.

Best wishes.

Upvotes: 1

Related Questions