Reputation: 2201
Hello Guys i am new to laravel. When the new user register with authentication i am this error message. How to resolve my problem The Authentication Failure with this error message.
Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\customer given.
My controller is
public function store(Request $request)
{
$user = new customer;
$user->name=Input::get('name');
$user->email=Input::get('email');
$user->password=Input::get('password');
$user->save();
Auth::login($user);
return redirect::home();
}
and my routes
Route::get('register', 'testing@index');
Route::post('store', 'testing@store');
Route::get('login', 'testing@create');
Route::post('logout', 'testing@destroy');
and my register page is
<form action="store" method="post">
<label for="name">Name</label>
<input type="text" name="name" autocomplete="off">
<br>
<label for="email">Email</label>
<input type="text" name="email" autocomplete="off">
<br>
<label for="password">Password</label>
<input type="text" name="password" autocomplete="off">
<br>
<input type="hidden" name="_token" value="{{csrf_token()}}">
<br>
<input type="submit" name="submit" value="Submit">
</form>
Please help me guys how to register,login and logout with complete authentation.
Thanks you and welcome your suggestions.
Upvotes: 0
Views: 411
Reputation: 6792
Without knowing your actual model of customer I try to give you the best matching answer.
If you are very new to laravel the best appraoch ist to use
php artisan make:auth
To create:
This will be done for you, using the default, already existing, App\User model. If you DO NOT want to user the default App\User and you want to use your App\Customer for authentication, then you will need to at least make your model extend Authenticable
use Illuminate\Foundation\Auth\User as Authenticatable;
class Customer extends Authenticatable
{
...
}
Without this you will surely receive the given error. However, you will still need to ensure that there are the required fields on your Customer model - like email, password, remember token etc. If you do not want to use these you will need to make further adaptions within your authentication controller.
As mentioned the best approach for beginners is using the generated auth. You can find more here: https://laravel.com/docs/5.2/authentication
Be careful - php artisan make:auth will create a few views and it will overwrite existing ones with the same name.
e.g.
and a few more within auth
Looking at your code you could simply try replacing
$user = new customer;
with
$user = new User
and ofcourse pull in the user model
use App\User;
Upvotes: 1