I want to have a route entry that dynamically handles requests based on the slug in the URL. I tried the code below, but the closure seems to be getting in the way. I replaced the closure with controller actions, too, and tried other options without success. The best I came up with thus far is below:
$bladeFiles = [
"about-us",
"join",
"contact",
];
foreach ($bladeFiles as $thisView) {
Route::get($thisView, function () {
global $thisView;
if (View::exists($thisView)) {
return view($thisView);
} else {
return redirect()->route('homepage');
}
})->name($thisView);
}
The issue with the above snippet is that global $thisView is always null inside the closure.
Thoughts?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2x86680
via IFTTT
Aucun commentaire:
Enregistrer un commentaire