夏期劇場
夏期劇場

Reputation: 18325

Laravel 5.2 : Fresh Install Authentication (Registration) not working

In Laravel 5.2 fresh installation, i'm trying to get the Authentication features (Register/ Login/ Logout/ etc), by following the documentations. Here are the steps i made.

# php artisan make:auth

Created View: /var/www/html/example.com/resources/views/auth/login.blade.php
Created View: /var/www/html/example.com/resources/views/auth/register.blade.php
Created View: /var/www/html/example.com/resources/views/auth/passwords/email.blade.php
Created View: /var/www/html/example.com/resources/views/auth/passwords/reset.blade.php
Created View: /var/www/html/example.com/resources/views/auth/emails/password.blade.php
Created View: /var/www/html/example.com/resources/views/layouts/app.blade.php
Created View: /var/www/html/example.com/resources/views/home.blade.php
Created View: /var/www/html/example.com/resources/views/welcome.blade.php
Installed HomeController.
Updated Routes File.
Authentication scaffolding generated successfully!

# cat app/Http/routes.php

<?php
use Illuminate\Http\Request;

Route::group(['middleware' => ['web']], function () {
    Route::get('/', function () {
        return view('welcome');
    });
});

Route::group(['middleware' => 'web'], function () {
    Route::auth();

    Route::get('/home', 'HomeController@index');
});

# php artisan migrate:install

Migration table created successfully.

# php artisan migrate

Migrated: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_100000_create_password_resets_table

(Here i'm not sure why it is dated as "2014", anyway.)

After this, i can already see below tables get created in my MySQL database:

[ So i assume the Database connection is also correct! ]
[ And also the Home page with "Login" "Register" "Login Form" etc are appeared, properly. ]

Problem

Now, when i go to /register there's a nice Registration Form already appeared. But when i fill-in and SUBMIT, nothing happens. (It keeps routed back to the /register page as nothing happened.)

Then when i checked from Apache Access Logs, the request is shown as "GET". I think this is supposed to be a "POST". Am i right?

(And nothing in the Error Logs as well)

What is happening please?

Upvotes: 1

Views: 1022

Answers (2)

夏期劇場
夏期劇場

Reputation: 18325

I got it solved by myself.

(1) It needs following functions in the app/Http/Controllers/AuthController.php:

public function getRegister()
{
    return $this->showRegistrationForm();
}

public function postRegister(Request $request)
{
    return $this->register($request);
}

(2) In the Router routes.php file, the function Route::auth(); call must be defined only after the other functions (under the same middleware group). Like:

Route::group(['middleware' => 'web'], function () {    
    Route::get('/home', 'HomeController@index');
    Route::auth();
});

( The Route::auth(); can not come first. )

Thanks all for all your kind helps :)

Upvotes: 2

Alexey Mezenin
Alexey Mezenin

Reputation: 163758

Try to remove web middleware, cause a lot of guys have issues with it past two weeks (since minor Laravel update). Now web middleware applies automatically to all routes and when you add it manually, it causes different kind of errors.

Upvotes: 1

Related Questions