Skip to content

laravel 11 issues #24

@arian-k84

Description

@arian-k84

hey so i tried using your package on laravel 11 but i was constantly getting errors when trying to generate a full farsi name related to your helper methods.

so i first tried creating an instance of Ybazli\Faker\Faker and use it's methods directly but i got this exception:
Cannot redeclare Ybazli\Faker\string() (previously declared in E:......\vendor\ybazli\faker\src\helper.php:7)

so i decided to investigate and i had to edit your code (which i really didn't like) to make it work, here is the fixed version:

<?php 
namespace Ybazli\Faker;

if (!\function_exists(__NAMESPACE__ . '\string')) {
    function string($value)
    {
        return (string)$value;
    }
}

if (!\function_exists(__NAMESPACE__ . '\randomNumber')) {
    function randomNumber($length = 20, $int = false)
    {
        $numbers = "0123456789";
        $number  = '';

        for ($i = 1; $i <= $length; $i++) {
            $num = $numbers[rand(0, strlen($numbers) - 1)];
            if ($num == 0 && $i == 1) {
                $i = 1;
                continue;
            }
            $number .= $num;
        }

        if ($int) {
            return (int)$number;
        }

        return string($number);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions