skip to Main Content

I don’t have any errors, nor on client or server. To give you more context I’m creating a login form, I’m trying to prevent the user from authenticate himself if the text he typed on the input fields are corrects. If it’s not correct, the user should not be redirected to the route (which has the name "authenticate").
there are 3 routes: login and home which are pages, and authenticate that’s redirecting to a controller which got all the functions related to the login.

AuthController

    <?php

namespace AppHttpControllers;
use IlluminateHttpRequest;

class AuthController extends Controller
{
    public function login() {
        return view('auth.login');
    }

    public function authenticate(Request $request)
    {
        $request->validate([
            'email' => 'required|email',
            'password' => 'required'
        ]);
    }
}

Login view

        <form action="{{ route('authenticate') }}" method="post">
          @csrf

          <input type="email" name="email">
          <input type="password" name="password">
          <button class="submit">Log</button>
        </form>

All the routes

    Route::get('home', HomeController::class)
    ->name('home');

Route::get('login', [AuthController::class, 'login'])
    ->name('login');

Route::get('authenticate', [AuthController::class, 'authenticate'])
    ->name('authenticate');

So basically what I’m trying to do is to check if the text the user has typed into the email field is an email, and if all the fields have text in it, because everything is required. But it seems like it’s not the case, even if the fields are empty the log in button redirects to the authenticate page. Did I do something wrong? If I didn’t provide enough information I would be glad to provide more, thanks for reading 🙂 have a nice day

2

Answers


  1. add required field to your input tag

    Login or Signup to reply.
  2. @if(Session::has('success'))
        <div class="alert alert-success alert-dismissible">
        {{Session::get('success')}}
        </div>
    @elseif(Session::has('failed'))
        <div class="alert alert-danger alert-dismissible">
        {{Session::get('failed')}}
        </div>
    @endif
        <div class="form-group">
        <label for="email" class="form-label">Email</label>
        <input type="email" name="email" class="form-control" value="{{old('email')}}" required />
        {!!$errors->first("email", "<span class='text-danger'>:message</span>")!!}
    </div>
    

    Try this…

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search