尝试播种数据库时会发生这种情况:
Seeding: UsersTableSeeder
array (
'name' => 'Tester One',
'email' => 'testerone@gmail.com',
'password' => 'Testing123',
Tester Two',esterone.png
)
数组的最后一个值显示下一个测试器的名称,并且由于某种原因,第一个测试器的图像的第一个字符被切断。接下来的测试人员甚至不会播种。当我查看数据库时,最后一列(名为' avatar')显示整个图像文件(所以testerone.png而不是esterone.png)以及测试者二的名称。
这是我的UsersTableSeeder.php
use Illuminate\Database\Seeder;
use League\Csv\Reader;
class UsersTableSeeder extends Seeder
{
public function run()
{
$path = resource_path() .'/postSeed/userseed.csv';
$reader = Reader::createFromPath($path, 'r');
$records = $reader->getRecords(['name', 'email', 'password', 'avatar']);
foreach ($records as $offset => $record) {
var_export($record);
DB::table('users')->insert([
'name' => $record['name'],
'email' => $record['email'],
'password' => bcrypt($record['password']),
'created_at' => date("Y-m-d H:i:s"),
'updated_at' => date("Y-m-d H:i:s"),
'avatar' => $record['avatar'],
]);
}
}
}
这就是我的CSV文件:
Tester One,testerone@gmail.com,Testing123,testerone.png
Tester Two,testertwo@gmail.com,Testing123,testertwo.jpg
Tester Three,testerthree@gmail.com,Testing123,testerthree.jpg
Tester Four,testerfour@live.be,Testing123,testerfour.jpg
Testert Five,testerfive@hotmail.com,Testing123,testerfive.jpg
Tester Six,testersix@stubru.be,Testing123,testersix.jpg
如果有人能帮助我,那就太棒了!