As previously asked I want to use different table(clients) for auth.
I have allready edited some codes, but still I am not able to use auth method.
I've tried too many variations but, still can't login with auth it after user register.
config/auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'client' => [
'driver' => 'session',
'provider' => 'clients',
]
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'clients' => [
'driver' => 'eloquent',
'model' => App\Client::class,
],
client modal file.
class Client extends Authenticatable
{
protected $guard = 'client';
public $timestamps = true;
protected $fillable = [
'email',
'password',
'fullname',
];
protected $hidden = [
'password', 'remember_token',
];
}
clients migration file.
Schema::create('clients', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('email')->unique();
$table->string('password');
$table->string('fullname');
$table->rememberToken();
$table->timestamps();
});
Controller
public function showRegister()
{
return view('pages.register');
}
public function doRegister(ClientRequest $request)
{
$validated = $request->validated();
$request->merge(['created_at' => Carbon::now()]);
$request->merge(['password' => Hash::make($request->password) ]);
$add = Client::create($validated);
auth('client')->attempt($add);
return redirect('my_profile')->with('success', 'success');
}
After submit register form I get this error.
Symfony\Component\Debug\Exception\FatalThrowableError
Argument 1 passed to Illuminate\Auth\SessionGuard::attempt() must be of the type array, object given, called in C:\wamp64\www\laravel\app\Http\Controllers\HomepageController.php on line 117
when I change my attempt code like this, It returns null.
auth('client')->attempt([
'email'=> $request->email,
'password'=> $request->password
]);
If
user
is getting created successfully try this line.Remove this line