Search code examples
laravellaravel-9laravel-seeding

function inside a seeder giving Call to undefined function Termwind\ValueObjects\mb_strimwidth()


i have a project where i have a 'habits' table, and that table needs a seeder to give it data, simply put, its a seeder with raw data, and i need to cook it, in other terms i need to process it like so...

public function run()
{
    $Habits = [
        '🙂Good' => ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'],
        '😐Neutral' => ['k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 't'],
        '☹️Bad' => ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
    ];
        
    foreach ($habits as $habit_category => $names) {
        foreach ($names as $name) {
            DB::table('habits')->insert([
                'name' => $name,
                'category' => $habit_category
            ]);
        }
    }
}

and here is the database seeder

public function run()
{
    $this->call([
        HabitsSeeder::class,
    ]);
}

i know the logic is not flawed, but idk if im doing it right but anyway, the error given is in the title:

"Call to undefined function Termwind\ValueObjects\mb_strimwidth()"


Solution

  • Try these options,

    • You can solve this issue by installing mbstring extension.

    If you have XAMPP try this,

    configphp ini → search for ;extension=mbstring → remove the semi colon (;) enter image description here

    If you have MAC OS,

    sudo port install php80-mbstring

    If you have Linux Based System,

    sudo apt-get install php8.1-mbstring

    Once the extenson is installed, you need to restart your PHP server.

    service httpd restart


    If you have any doubt please refer this blog, https://sebhastian.com/mbstring-missing-php/

    or you can simply prefer PHP documentation https://www.php.net/manual/en/mbstring.installation.php