Home » Php » php – How to properly create a sign up and a sign in form on laravel 6 on the same page?

php – How to properly create a sign up and a sign in form on laravel 6 on the same page?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a form on my front_page for logging in and signing up on the same page. The forms are:

{!! Form::open(['route' => 'auth.login']) !!}
    {!! Form::email('email', $value = null, ['class' => 'form-control signup_field', 'placeholder' => 'Email Address']) !!}
    {!! Form::password('password', ['class' => 'form-control signup_field', 'required', 'placeholder' => 'Password']) !!}
    {!! Form::submit('Sign in', ['class' => 'btn sign_up_btn']) !!}
    {!! csrf_field() !!}
{!! Form::close() !!}

{!! Form::open(['route' => 'auth.register']) !!}
    <div class="row signup_form">
        <div class="col-md-3">
            {!! Form::email('email', $value = null, ['class' => 'form-control signup_field', 'placeholder' => 'Email Address']) !!}
        </div>
        <div class="col-md-3">
            {!! Form::password('password', ['class' => 'form-control signup_field', 'required', 'placeholder' => 'Password']) !!}
        </div>
        <div class="col-md-3">
            {!! Form::email('paypal_email', $value = null, ['class' => 'form-control signup_field', 'placeholder' => 'Paypal Email Adress']) !!}
        </div>
        <div class="col-md-3">
            {!! Form::submit('Sign up', ['class' => 'btn sign_up_btn']) !!}
        </div>
    </div>
    @if($errors->any())
        @foreach($errors->all() as $error)
            <div class="alert alert-danger">
                 <strong>Error!</strong> {{$error}}
             </div>
         @endforeach
     @endif
    {!! csrf_field() !!}
{!! Form::close() !!}

My routes file:

Route::post('/', 'Auth\[email protected]')->name('auth.register');
Route::post('/', 'Auth\[email protected]')->name('auth.login');

[email protected]:

public function create(Request $request) {
    $create = User::create([
        'email' => $request['email'],
        'paypal_email' => $request['paypal_email'],
        'password' => Hash::make($request['password']),
    ]);
    if($create){
        return redirect('/home');
    }
}

[email protected];

How to define it properly?

So the question is, how to properly define my routes file, [email protected] method and [email protected] method? I saw a lot of information how to fix those forms, so the main questions are these.

How to&Answers: