dimanche 14 juin 2015

FatalErrorException: Call to a member function count() on a non-object

I'm trying to generate a unique/random string in Laravel 5 and check it through my table to see if it exists.

This is what I have, but it seems to be giving the error stated in the title:

    public static function generate()
    {
        $exists = true;
        while ($exists) {
            $code = str_random(15);
            $check = self::where('code', $code)->first();
            if( ! $check->count()){
                $exists = false;
            }
        }
        return $code;
    }

Anyone know why it's giving this error?




Aucun commentaire:

Enregistrer un commentaire