文章分类由1变多

This commit is contained in:
2021-04-02 09:30:56 +08:00
parent e2699b7e04
commit 977dd11c7d
19 changed files with 177 additions and 287 deletions

View File

@@ -2,6 +2,9 @@
namespace App\Http\Controllers;
use App\Models\Article;
use App\Models\ArticleCategory;
class TestController extends Controller
{
@@ -10,4 +13,20 @@ class TestController extends Controller
}
public function set_article_category()
{
$articles = Article::whereHas('category')
->chunk(200, function ($articles) {
foreach ($articles as $article) {
ArticleCategory::create([
'article_id' => $article->id,
'category_id' => $article->category_id,
]);
}
});
return true;
}
}