1.Laravel在truncate表的时候,如果有外键,先把约束检查关掉再清空表。如:
<code>
DB::statement('SET FOREIGN_KEY_CHECKS = 0');
DB::table('members')->truncate();
DB::table('stores')->truncate();
DB::table('products')->truncate();
DB::statement('SET FOREIGN_KEY_CHECKS = 1');
</code>
2.递归删除一个文件夹,该文件夹不为空:
/**
function rmdir_recursive($dir){
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($files as $file) {
if ($file->isDir()) {
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
}
}
return rmdir($dir);
}
正文完