1
votes

I am working with Laravel 5.5. I created login/register page with make:auth about 1 month ago and didn't change anything inside Laravel auth core files. I just register and, after that I want to login. Login page reloaded when I hit login button and don't give any error messages. I don't know what's wrong. This code worked during 1 month and from yesterday it doesn't work right. I just attached my login/register files here.

Auth Register Controller

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;

class RegisterController extends Controller {

use RegistersUsers;

protected $redirectTo = '/home';

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

protected function validator(array $data)
{
    return Validator::make($data, [
        'member_id' => 'required|string|integer|min:000000|max:999999',
        'password' => 'required|string|min:6|confirmed',
    ]);
}

protected function create(array $data)
{
    return User::create([
        'member_id' => $data['member_id'],
        'password' => bcrypt($data['password']),
    ]);
}

This is my register.blade.php

<form class="form-horizontal" method="POST" action="{{ route('register') }}">
   {{ csrf_field() }}
<div class="form-group{{ $errors->has('member_id') ? ' has-error' : '' }}">
    <label for="member_id" class="col-md-4 control-label">
        {{ Lang::get('all.info.member_id') }}
    </label>

    <div class="col-md-6">
        <input id="member_id" type="number" onkeypress='return event.charCode >= 48 && event.charCode <= 57' class="form-control" name="member_id" value="{{ old('member_id') }}" required> 
        @if ($errors->has('member_id'))
            <span class="help-block">
                <strong>{{ $errors->first('member_id') }}</strong>
            </span>
        @endif
    </div>
</div>

<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
    <label for="password" class="col-md-4 control-label">
        {{ Lang::get('all.info.password') }}
    </label>

    <div class="col-md-6">
        <input id="password" type="password" class="form-control" name="password" required> 
        @if ($errors->has('password'))
            <span class="help-block">
                <strong>{{ $errors->first('password') }}</strong>
            </span>
        @endif
    </div>
</div>

<div class="form-group">
    <label for="password-confirm" class="col-md-4 control-label">
        {{ Lang::get('all.info.confirm_password') }}
    </label>

    <div class="col-md-6">
        <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
    </div>
</div>

</form>

This is my login.blade.php

<form class="form-horizontal" method="POST" action="{{ route('login') }}">
    {{ csrf_field() }}

    <div class="form-group{{ $errors->has('scout_id') ? ' has-error' : '' }}">
       <label for="scout_id" class="col-md-4 control-label">
          {{ Lang::get('all.login_p.scout_id') }}
       </label>

       <div class="col-md-6">
           <input id="member_id" type="number" onkeypress='return event.charCode >= 48 && event.charCode <= 57' class="form-control" name="member_id" value="{{ old('member_id') }}" required autofocus>

           @if ($errors->has('member_id'))
               <span class="help-block">
                   <strong>{{ $errors->first('member_id') }}</strong>
               </span>
           @endif
        </div>
    </div>

    <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
        <label for="password" class="col-md-4 control-label">
            {{ Lang::get('all.login_p.password') }}
        </label>

        <div class="col-md-6">
           <input id="password" type="password" class="form-control" name="password" required>

           @if ($errors->has('password'))
              <span class="help-block">
                  <strong>{{ $errors->first('password') }}</strong>
              </span>
           @endif
        </div>
     </div>

    <div class="form-group">
         <div class="col-md-8 col-md-offset-4">
             <button type="submit" class="btn btn-primary">
                 {{ Lang::get('all.login') }}
             </button>
         </div>
    </div>
</form>
2
did you enable debug mode? - madalinivascu
yeah, in .env file APP_DEBUG=true but i don't get any error. Page just reload , member_id field filleb with old value, but password is cleared. doesn't show up any error messages - rufatZZ
that means your form has validation errors and you aren't showing/viewing them on the page - madalinivascu
its okay, main question is: why did i not see any problem like this till now? Because i didn't change anything :( - rufatZZ
don't know,maybe you erased the translation for that lang, a coma in the wrong place, who knows - madalinivascu

2 Answers

3
votes

did you use Auth::attempt(); ?

Auth::attempt(['member_id' => $request->member_id, 'password' => $request->password]);

2
votes

You are not telling the LoginController that your 'email'/'username' field is not email. You have to tell it you want to use a different field.

Username Customization

"By default, Laravel uses the email field for authentication. If you would like to customize this, you may define a username method on your LoginController:"

public function username()
{
    return 'member_id';
}

Laravel 5.5 Docs - Authentication - Authentication Quickstart - Authenticating