I have a plethora of redirects I would like to generate somewhat dynamically.
My idea is to store them in an array like
$pagesFromOldSite = [
[
'pattern' => [ 'company-partners', 'partners', 'product/graph-databases' ],
'target' => 'about/ecosystem/partners',
],
[
'pattern' => [ 'publication', 'publications', 'research/publications' ],
'target' => 'about/ecosystem/publications',
],
];
—as that is more readable IMO—and then loop through them like this:
foreach ($pagesFromOldSite as $route):
$routes[] = [
'pattern' => $route['pattern'],
'action' => function() {
$page = page($route['target']);
if(!$page) $this->next();
go($page, 301);
}
];
endforeach;
where $routes is the array of all routes, of course.
This doesn’t work, obviously.
But can I pass $route['target'] as a variable to the action and if so, how?
I have tried 'action' => function($target = $route['target']) {, but to non avail.