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 TermwindValueObjectsmb_strimwidth()"
2
Answers
The error message is probably unrelated to your seeder. You’re using the
nunomaduro/termwind
package, which is most likely referenced inside of a service provider.When you call any artisan command like
db:seed
, those service providers are being booted up and any errors in them will block the seeder from even running.The only place that package calls the
mb_strimwidth
inside the ValueObjects namespace is in this file:https://github.com/nunomaduro/termwind/blob/8ab0b32c8caa4a2e09700ea32925441385e4a5dc/src/ValueObjects/Styles.php#L1053
Really the root issue is that you are missing the
mbstring
PHP extension. So when the Termwind package references anmb_*
method, it can’t find that method in the global namespace and instead checks the package’s namespace, can’t find it there either, and throws an error.Take a look at the PHP docs for how to install the
mbstring
package in your system.Tip for debugging a future issue like this is to look at the entire error message stack trace not just the latest message. You’ll be able to work backwards and see where this method is being called and what triggered it.
Try these options,
If you have XAMPP try this,
If you have MAC OS,
If you have Linux Based System,
Once the extenson is installed, you need to restart your PHP server.
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