hello .
i want set variable to chunk loop and get this variable but set value of $n don't work .
$n = 1;
$tags = \DB::table('posts')
->leftJoin('post_tag', 'posts.id', '=', 'post_tag.post_id')
->leftJoin('tags', 'tags.id', '=', 'post_tag.tag_id')
->orderBy('posts.updated_at' , 'DESC')
->select('posts.created_at as ptc','posts.id', 'posts.updated_at as ptu', 'posts.title','tags.created_at','tags.updated_at as tgc','tags.title')
->groupBy('tags.id')
->chunk(500, function ($tags) use($sitemap , $n) {
$lastUpdate = $tags->max('ptu');
$listSiteMapBlogs[] = $lastUpdate;
$sitemap->addSitemap(\URL::to('tags-sitemap.xml?page='.$n) , $lastUpdate);
$n++;
});
@m-alinasab, $n isn't being incremented because PHP is passing $n by value, which is the default behavior for everything in PHP with the exception of objects and resources, I believe. If you want this to work, you just need to change your use statement to use($sitemap, &$n), which will pass $n by reference.
Please ask questions on the forums, this repo is for bug reporting only.
Most helpful comment
@m-alinasab,
$nisn't being incremented because PHP is passing$nby value, which is the default behavior for everything in PHP with the exception of objects and resources, I believe. If you want this to work, you just need to change your use statement touse($sitemap, &$n), which will pass$nby reference.