I installed the php artisan ui vue --auth to use completely the login/register that laravel auth offers to me.
But I don't want the default users migration table, I want my custom table called Usuarios with the same number of fields but with other names.
I wanna use all auth laravel offers to me changing the minimum, so I'm trying to use the same RegisterController.php and User.php.
I read so much about this and everyone say that I must do simple changes in these 2 .php but it doesn't work.
When I submit the data there is no one error, it just the register form submit don't work. The page refresh but nothing happens, don't save data and nothing appears in console.
RegisterController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
/* users datatable fields */
// 'name' => 'name' => ['required', 'string', 'max:255'],
// 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
// 'password' => ['required', 'string', 'min:8', 'confirmed'],
/* Usuarios datatable fields */
'USU_NICKNAME' => ['required', 'string', 'max:255'],
'USU_EMAIL' => ['required', 'string', 'email', 'max:255', 'unique:Usuarios'],
'USU_PASSWORD' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\Models\User
*/
protected function create(array $data)
{
return User::create([
/* users datatable fields */
// 'name' => $data['name'],
// 'email' => $data['email'],
// 'password' => Hash::make($data['password']),
/* Usuarios datatable fields */
'USU_NICKNAME' => $data['name'],
'USU_EMAIL' => $data['email'],
'USU_PASSWORD' => Hash::make($data['password']),
]);
}
}
User.php
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
/* Usuarios table */
protected $table = 'Usuarios';
/**
* The attributes that are mass assignable.
*
* @var string[]
*/
protected $fillable = [
/* users datatable fields */
// 'name',
// 'email',
// 'password',
/* Usuarios datatable fields */
'USU_NICKNAME',
'USU_EMAIL',
'USU_PASSWORD',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
web.php
<?php
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/welcome', function () {
return view('welcome');
});