Support the ongoing development of Laravel.io →
Authentication Input Views
Last updated 2 years ago.
0

There are a number of ways to solve this issue, here are two that you could explore.

  1. You can rewrite the methods so they use different error message bags
  2. based on what the user was trying to do, you can tell the previous page they were either a) logging it or b) signing up and that can determine which side to show the messages.
0

I'm newbie on Laravel. Using 5.2. I'm not sure how to do it.

can you please show me how to do it?

0

After searching for days I found a solution to achieve this. But I don't know it its the best way to do it. Anyway, here what i did--

in AuthController.php i added the below functions

public function login(Request $request) {
        if (Auth::attempt ( array (
                'username' => $request->get ( 'login-username' ),
                'password' => $request->get ( 'login-password' ) 
        ) )) {
            session ( [ 
                    'username' => $request->get ( 'login-username' ) 
            ] );
            return Redirect::back ();
        } else {
            Session::flash ( 'message-login', "Invalid Username or Password , Please try again." );
            return Redirect::back ();
        }
    }

    public function logout() {
        Session::flush ();
        Auth::logout ();
        return Redirect::back ();
    }

Then in view file (i used in home.blade.php) this is what i've--

<div class="row">
    <div class="col-sm-6">
        <div class="form-box">
            <div class="form-top">
                <div class="form-top-left">
                    <h3>Login to our site</h3>
                    <p>Enter username and password to log on:</p>
                </div>
            </div>
            <div class="form-bottom clearfix">
                @if (Session::has('message-login'))
                    <div class="alert alert-danger alert-dismissible " style="font-size:15px;">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
                        {{ Session::get('message-login') }}
                    </div>
                @endif
                <form role="form" method="POST" action="{{ url('/login') }}">
                    {{ csrf_field() }}

                    <div class="form-group {{ $errors->has('login-username') ? ' has-error' : '' }}">
                        <input  type="text" class="form-control" placeholder="Username" name="login-username" value="{{ old('username') }}">
                        @if ($errors->has('login-username'))
                            <span class="help-block">
                                {{ $errors->first('login-username') }}
                            </span>
                        @endif
                    </div>

                    <div class="form-group {{ $errors->has('login-password') ? ' has-error' : '' }}">
                        <input type="password" class="form-control" name="login-password" placeholder="Password">
                        @if ($errors->has('login-password'))
                            <span class="help-block">
                                {{ $errors->first('login-password') }}
                            </span>
                        @endif
                    </div>

                    <div class="form-group">
                        <div class="checkbox">
                            <label>
                                <input type="checkbox" name="remember"> Remember Me
                            </label>
                        </div>
                    </div>

                    <div class="form-group">
                        <button type="submit" class="btn btn-block btn-primary btn-lg"><i class="fa fa-sign-in"></i> Sign in!</button>
                        <br/>
                        <a class="pull-right" href="{{ url('/password/reset') }}">Forgot Your Password?</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
    
    <div class="col-sm-6">
        <div class="form-box">
            <div class="form-top">
                <div class="form-top-left">
                    <h3>Sign up now</h3>
                    <p>Fill in the form below to get instant access:</p>
                </div>
            </div>
            <div class="form-bottom">
                @if (count($errors) > 0)
                    <div class="alert alert-danger">
                        <strong>Whoops!</strong> There were some problems with your input.<br><br>
                        <ul>
                            @foreach ($errors->all() as $error)
                                <li>{{ $error }}</li>
                            @endforeach
                        </ul>
                    </div>
                @endif
                <form role="form" method="POST" action="{{ url('/register') }}">
                    {{ csrf_field() }}

                    <div class="form-group">
                        <input id="name" type="text" class="form-control" placeholder="Your Name" name="name" value="{{ old('name') }}">
                    </div>

                    <div class="form-group">
                        <input id="username" type="text" class="form-control" placeholder="Username" name="username" value="{{ old('username') }}">
                    </div>

                    <div class="form-group">
                        <input id="email" type="email" class="form-control" placeholder="E-Mail Address" name="email" value="{{ old('email') }}">
                    </div>

                    <div class="form-group">
                        <input id="password" type="password" class="form-control" name="password" placeholder="Password">
                    </div>

                    <div class="form-group">
                        <input id="password_confirmation" type="password" class="form-control" name="password_confirmation" placeholder="Confirm Password">
                    </div>

                    <div class="form-group">
                        <button type="submit" class="btn btn-block btn-success btn-lg"><i class="fa fa-user-plus"></i> Register</button>
                    </div>
                </form>
            </div>
        </div>
        
    </div>
</div>
0

thanks for the solution i had same problem with very same website http://indiitacademy.com/ and the solution work like charm

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.