0

Hice un login por mi cuenta usando Laravel y por alguna razón la ruta NO funciona y da error 404, no sé porque ocurre esto, intente reescribir el login varias veces y sigue con lo mismo

Esto es lo que tengo un index.blade.php

<!DOCTYPE html>

<head>

<meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title>Sistema de estudiantes</title>

    <!-- Bootstrap core CSS -->
    <script src="{{ url('/js/jquery.min.js') }}"></script>
    <link rel="stylesheet" type="text/css" href="{{ url('/css/bootstrap-4.5.0-dist/css/bootstrap.css') }}">
    <script src="{{ url('/css/bootstrap-4.5.0-dist/js/bootstrap.js') }}"></script>
    <link rel="stylesheet" type="text/css" href="{{ url('/css/login.css') }}">
</head>

<body>
<center>
<div class="wrapper fadeInDown">
  <div id="formContent">
    <!-- Tabs Titles -->

    <!-- Login Form -->
    <form action="{{url('doLogin')}}">
    {{ csrf_field() }}
      <br></br>
      <h2>Coloque sus datos</h2>
      <br></br>
      <p>Nombre </p><input required type="text" id="name" class="fadeIn second" name="name" placeholder="login">
      @if ($errors->has('name'))
                  <span class="error">{{ $errors->first('name') }}</span>
      @endif 
      <br></br>
      <br></br>
      <p>Email </p><input required type="email" id="email" class="fadeIn second" name="email" placeholder="[email protected]">
      @if ($errors->has('email'))
                  <span class="error">{{ $errors->first('email') }}</span>
      @endif 
      <br></br>
      <br></br>
      <p>Clave </p><input required type="password" id="password" class="fadeIn third" name="password" placeholder="password">
      @if ($errors->has('password'))
                  <span class="error">{{ $errors->first('password') }}</span>
        @endif 
      <br></br>
      <input type="submit" id="entrar" name="entrar" class="fadeIn fourth" value="Entrar">
    </form>

    <!-- Remind Passowrd -->
    <div id="formFooter">
      <a class="underlineHover" href="#">Olvido su clave?</a>
    </div>

  </div>
</div>
</center>
</body>
</html>

Esto es lo que tengo en el UserController.php

<?php

namespace App\Http\Controllers;
 
use Illuminate\Http\Request;
use Validator,Redirect,Response;
Use App\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Session;


class UserController extends Controller
{

  public function doLogin()
  {
  // validate the info, create rules for the inputs
  $rules = array(
      'email'    => 'required|email', // make sure the email is an actual email
      'password' => 'required|alphaNum|min:3' // password can only be alphanumeric and has to be greater than 3 characters
  );
  
  // run the validation rules on the inputs from the form
  $validator = Validator::make(Input::all(), $rules);
  
  // if the validator fails, redirect back to the form
  if ($validator->fails()) {
      return Redirect::to('index')
          ->withErrors($validator) // send back all errors to the login form
          ->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form
  } else {
  
      // create our user data for the authentication
      $userdata = array(
          'email'     => Input::get('email'),
          'password'  => Input::get('password')
      );
  
      // attempt to do the login
      if (Auth::attempt($userdata)) {
  
          // validation successful!
          // redirect them to the secure section or whatever
          // return Redirect::to('secure');
          // for now we'll just echo success (even though echoing in a controller is bad)
          echo 'SUCCESS!';
  
      } else {        
  
          // validation not successful, send back to form 
          return Redirect::to('index');
  
      }
  
  }
  }

      public function estudiantes()
      {
   
        if(Auth::check()){
          return view('estudiantes');
        }
         return Redirect::to("index")->withSuccess('Opps! You do not have access');
      }

}

Estas son mis rutas en web.php

Route::get('/', function () {
    return view('index');
});

Route::post('index', array('uses' => 'UserController@doLogin'));

Esto es lo que tengo en el model del usuario, User.php

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

Esta es mi migracion en la base de datos

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });
}

Me gustaria ver si hay una manera de reescribir el login o hacer que esto funcione porque hace tiempo que no estudio Laravel. Estoy usando Laravel 6.18.25

4
  • Route::post('index', array('uses' => 'UserController@doLogin')); ¿ uses, user, users?
    – Triby
    Commented el 21 jul. 2020 a las 22:52
  • El ejemplo decia 'uses'
    – Shredder
    Commented el 21 jul. 2020 a las 23:02
  • En la uri de tu ruta dice index, pero en el action del form usas doLogin Commented el 22 jul. 2020 a las 0:58
  • <form action="{{url('doLogin')}}"> doLogin no es una ruta en web.php Commented el 22 jul. 2020 a las 2:15

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.