To connect your renamed class as the app's authentication model, you'll also need to edit config/auth.php and update the providers.users.model key. There may be additional adjustments necessary, but this should at least get your app talking to the right table when a login attempt is made.
Illuminate\Foundation\Auth\User - Technical question
Hello everyone. I have a technical question about the bases of laravel. Laravel when creating a new project creates the table, model and controller User by default. The problem is that I don't want it to be called user but ciudadano. Since I don't know how to delete everything that is user, I create a new migration, model and controller called ciudadano.
this is the ciudadano's model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\Ciudadano as Authenticatable;
class Ciudadano extends Authenticatable
{
protected $table = 'ciudadanos';
protected $fillable =[
'cuil',
'nombre',
'apellido',
'email',
'password',
];
protected $hidden = [
'password',
'remember_token',
];
protected $casts = [
'email_verified_at' => 'datetime',
];
}
As you can see, I want citizen to extend the Authenticatable model. But When there is a new entry, I get:
Class "Illuminate\Foundation\Auth\Ciudadano" not found
But If I set: use Illuminate\Foundation\Auth\User as Authenticatable;
I get:
'Call to undefined method App\Models\Ciudadano::createToken()
My question is:
Is it correct if I set the Illuminate\Foundation\Auth\User usage to Authenticable? Because I don't use user model and user controller. But I'm using ciudadano.
You can see here the ciudadano controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Ciudadano;
use App\Mail\MyMailable;
use Mail;
class CiudadanoController extends Controller
{
public function store(Request $request)
{
try {
$validated = $this->validate($request, [
'cuil' => 'required',
'nombre' => 'required',
'apellido' => 'required',
'email' => 'required',
'password' => 'required',
]);
$ciudadano = Ciudadano::create($validated);
$ciudadano->confirmation_code=random_int(1000,9999);
$ciudadano->save();
Mail::to('[email protected]')
->cc('[email protected]')
->queue((new MyMailable($ciudadano))->from('[email protected]', 'Laravel'));
return response()->json([
'status' => true,
'message' => 'User Created Successfully',
'token' => $ciudadano->createToken("API TOKEN")->plainTextToken
], 200);
} catch (\Throwable $th) {
return response()->json([
'status' => false,
'message' => $th->getMessage()
], 500);
}
}
public function validateEmail(Request $request)
{
$validated = $this->validate($request, [
'cuil' => 'required',
'confirmation_code' => 'required',
]);
}
}
Please or to participate in this conversation.