I'm very new to Laravel and PHP 5.4, coming from CI. Please forgive this stupid question about very basic authentication.
I am beginning by implementing login/registration (authentication), following the docs.
My migration is in place:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('email')->unique();
$table->string('password', 60);
$table->string('first_name');
$table->string('last_name');
$table->rememberToken();
...
});
Here's my config\auth.php:
'driver' => 'eloquent',
'model' => App\User::class,
'table' => 'users',
'password' => [
'email' => 'emails.password',
'table' => 'password_resets',
'expire' => 60,
],
app\User.php:
protected $table = 'users';
protected $fillable = ['first_name', 'last_name', 'email', 'password'];
protected $hidden = ['password', 'remember_token'];
app\Http\Controllers\Auth\AuthController.php:
protected function validator(array $data) {
return Validator::make($data, [
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
protected function create(array $data) {
return User::create([
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
public function getLogin() {
return view('admin/login');
}
public function getRegister() {
return view('admin/register');
}
app\Http\routes.php:
Route::get('admin/login', 'Auth\AuthController@getLogin');
Route::post('admin/login', 'Auth\AuthController@postLogin');
Route::get('admin/register', 'Auth\AuthController@getRegister');
Route::post('admin/register', 'Auth\AuthController@postRegister');
My views are displaying properly:
resources/views/admin/login.blade.php
resources/views/admin/register.blade.php
with forms:
<form action="/admin/login" method="POST">
<form action="/admin/register" method="POST">
This is as far as I get. The Register form, when submitted, just redirects to itself, no errors. No entries are created in the users database table.
What am I missing?
EDIT
I don't think I need to add a postRegister() because it's already defined in the RegistersUsers trait used by AuthenticatesAndRegistersUsers used by AuthController.
Also, not sure if this helps but I have 2 virtual hosts pointing to the same project directory.
storage/logs/laravel.log, make sure you have set error_reporting(E_ALL), also check server logs - Ganesh GhalamepostRegister()method considering thats the method your posting to.. or are you using the defaults? Also, check the network tab of your browsers developer tools, should tell you the response you got from the post request, which should hint at why you were redirected. - JeemusuGETinstead ofPOST, even though the<form action="/admin/register" method="POST">. Any idea why this is so? - ObayPOST, but status is302 Found. Then it makes theGET- Obay