文章分类由1变多
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user