table('cases')->get(); $categoryArr = [ 0=> 'examples', 1=> 'services', 2=> 'news', ]; foreach($oldArticles as $article){ //处理富文本内容图片地址; $_content = null; if($article->content){ $_content = str_replace('http://www.gxflqj.cn/', 'http://www.gxflqj.cn/storage', $article->content); } $_article = [ 'id' => $article -> id, 'category' => $categoryArr[$article -> type ?? 0], 'title' => $article->title, 'cover' => $article->img, 'content' => $_content, 'published_at' => now(), 'sort' => $article -> sort ?? 0, 'is_recommend' => $article->recommend, 'is_enable' => 1, 'created_at' => now(), 'updated_at' => now(), ]; $articles[] = $_article; } if(count($articles) > 0){ DB::table('articles')->truncate(); try { DB::begintransaction(); DB::table('articles')->insert($articles); DB::commit(); } catch (Throwable $th) { DB::rollBack(); report($th); } } } }