I need to seed Reg-Ex patterns in SqLite database. I'm using Laravel 7. Here is my seeder:
<?php
use App\PhoneValidetionRules;
use Illuminate\Database\Seeder;
class PhoneValidetionRulesSeeder extends Seeder
{
public function run()
{
$rules = '
{
"iPhone": "\\biPhone\\b|\\biPod\\b",
"BlackBerry": "BlackBerry|\\bBB10\\b|rim[0-9]+|\\b(BBA100|BBB100|BBD100|BBE100|BBF100|STH100)\\b-[0-9]+",
"HTC": "HTC|HTC.*(Sensation|Evo|Vision|Explorer|6800|8100|8900|A7272|S510e|C110e|Legend|Desire|T8282)|APX515CKT|Qtek9090|APA9292KT|HD_mini|Sensation.*Z710e|PG86100|Z715e|Desire.*(A8181|HD)|ADR6200|ADR6400L|ADR6425|001HT|Inspire 4G|Android.*\\bEVO\\b|T-Mobile G1|Z520m|Android [0-9.]+; Pixel",
"Nexus": "Nexus One|Nexus S|Galaxy.*Nexus|Android.*Nexus.*Mobile|Nexus 4|Nexus 5|Nexus 6"
}';
$data = [];
foreach (json_decode($rules, true) as $key=>$value){
$data[] = [
'name' => $key,
'regex' => $value
];
}
PhoneValidetionRules::insert($data);
}
}
When I seed it, all \bare converted to \x08. Here is database:
Here is table blueprint:
Schema::create('phone_validetion_rules', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('regex');
});
If I update regex from PhpStorm manually, It insert correctly. How can I insert Reg-Ex to database using Laravel Seeder?
