Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

laravel checking user enbaled always true for positive integer

Returning always true in laravel user model for positive integer

class User extends .....
{
protected $casts = [
        'email_verified_at' => 'datetime',
    'enabled' => 'boolean',
    ];



public function isEnabled(): bool
    {
        return $this->enabled == 1 ? true : false;
    }

}

in MySQL Table

enabled is tinyint unsigned

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

in controller

$user->isEnabled() //Returning always true in laravel user model for positive integer

>Solution :

You have set enabled feld as tinyint and you have said true for all positve integer ; so rewrite as below

protected $casts = [
        'email_verified_at' => 'datetime',
    'enabled' => 'boolean', // remove this line  as you casting enabled as boolen which returns true on positive integer
    ];

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading