You can customize the table on:
database/migrations/***_create_users_table.php
To redirect the User model to a different table name you can set:
protected $table = 'bb_user';
on the user model
app/User.php
Also in the user model change the fillable fields as you need them:
protected $fillable = [
'name', 'lastname', 'usermail', 'userpassword',
];
To change the database name you can modify on .env file.
Keep in mind that if you do such changes you also need to modify the Views in:
resources/views/auth/login.blade.php
resources/views/auth/register.blade.php
changing the inputs like:
<div class="input-group">
<input id="usermail" type="email" class="form-control {{ $errors->has('usermail') ? ' is-invalid' : '' }}" placeholder="{{ __('User Mail') }}" name="usermail" autofocus value="{{ old('usermail') }}">
@if ($errors->has('usermail'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('usermail') }}</strong>
</span>
@endif
</div>
Same for 'userpassword'.
When you want to display the data you would do so:
{{ Auth::user()->usermail }}
In your blade templates.
Hope this helps. Happy coding.
Daniel
alfirus liked this reply
Lol happy to help, and BTW it would be
@if ($Daniel == "near")
{{ "French kiss" }}
@endif
But that's gay lol.
Hi,
I tried your solution and double check it. However i can't register. It back to register page without error. -.-"
Forgot to tell you about controllers, remember you are using a MVC architecture. In:
app\Http\Controllers\Auth\LoginController.php
app\Http\Controllers\Auth\RegisterController.php
add:
public function usermail(){
return 'usermail';
}
The authenticate() method in LoginController would be:
public function authenticate(Request $request)
{
$credentials = $request->only('usermail', 'userpassword');
if (Auth::attempt($credentials)) {
// Authentication passed...
return redirect()->intended('/home');
}
if(!Auth::user())
{
return redirect('/login'); // add your desire URL in redirect function
}
}
In the RegisterController the 'validator()' method would be:
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'useremail' => ['required', 'string', 'email', 'max:255', 'unique:users'], //<- HERE THE UNIQUE: IS THE USERS TABLE NAME
'userpassword' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
And the create() method would be:
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'usermail' => $data['usermail'],
'userpassword' => Hash::make($data['userpassword']),
]);
return $user;
}
And I guess that's all.
Happy coding!
Daniel
Now we have a progress
https://flareapp.io/share/87nB6e7w#F58
It seems it still want to connect with "users" table.
Did you change name of the table on the migration?
database/migrations/****_create_users_table.php
Check for your factory as well in
database/factories/ModelFactory.php
Did you change the name of the table on.. ?
app/User.php
protected $table = 'users';
Also check this file
config/auth.php
and change the field 'users'. If that doesnt work add this at the begining
/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/
'table' => 'users',
Make sure you run
php artisan migrate:fresh --seed
Morning bro,
Yup, i checked all and get error
Illuminate\Database\QueryException SQLSTATE[42S02]: Base table or view not found: 1146 Table 'alfirus_fldata.users' doesn't exist
It still keep trying to connect with users table
add this at the begining of config/auth.php
/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/
'table' => 'users',
this should do the trick.
Sadly that won't do the trick
Illuminate\Database\QueryException SQLSTATE[42S02]: Base table or view not found: 1146 Table 'alfirus_fldata.users' doesn't exist (SQL: select count(*) as aggregate from
users
whereuseremail
= [email protected])
I need to see your code, not only the error. post it up and we'll deep into your problem.
Use this please
https://paste.laravel.io
Just dont include the .env file
I'm using codeanywhere which i can share all files and structures, much better i guess
You got it now am i wrong?
I just register to your app!
Congrats. Can you tell me what whas the problem?
I delete everything and use default database and tables because I need to learn something.
Will create another sub domain to tackle the custom user database and tables later.
Cool bro,
Check this out.
https://www.5balloons.info/changing-authentication-table-laravel/
Nice tutorial right there.
Happy coding. Daniel
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community