Search code examples
phpauthenticationlaravel-5.1soft-delete

Laravel 5.1 Auth::attempt() not working if User has softdelete attribute


It's working if there is no softdelete attribute on User model. Here is my code:

User model:

.....
use Authenticatable, Authorizable, CanResetPassword, SoftDeletes;
protected $dates = ['deleted_at'];
protected $softDelete = true;
.....

AuthController:

........
$userdata = ['email' => Input::get('email'), 'password' => Input::get('password'), 'active' => 1];
$authRemember = (Input::get('auth_remember'))? true : false;

// if (Auth::validate($userdata)) {
    if (Auth::attempt($userdata, $authRemember)) {
        echo 'success';
    }else{
        echo 'failed';
    }
// }else{
//  echo 'failed';
// }
.....

I already set deleted_at TIMESTAMP and active TINYINT to my users table. any help would be appreciated.

Resolved it's worked after I set the default value to NULL for the deleted_at column and remove 'active' => 1 from the code above


Solution

  • Does it not work if the User is softDeleted or even if the deleted_at is null? A bit more information will be great. Does an error occur?

    And are you sure that the deleted_at is null? We had A similar problem and the solution was that we trimed all columns and that brings the deleted_at to A not empty value.