Answer the question
In order to leave comments, you need to log in
How to write database-related routes in Laravel 5?
Routes:
Route::any('/', function () {
return redirect()->route('getpage', ['index']);
});
Route::any('{requestedPage}/{requestedSubPage?}', [
'as' => 'getpage',
'uses' => '[email protected]'
]);
public function getpage($requestedPage = 'index', $requestedSubPage = null)
{
$wantedPage = $requestedSubPage ? $requestedSubPage : $requestedPage;
$page = Pages::findByUrlOrFail($wantedPage);
if (is_null($page)) {
abort(404);
}
$page = $page->toArray();
if ($page['type'] == 'static') {
return view('pages.static')->with($page);
}
return redirect()->action('App\Http\Controllers\[email protected]'); // Эта строка не работает, почему-то
}
Answer the question
In order to leave comments, you need to log in
So in your example above, you have redirect()->route('getpage', ['index']);
And when you call action, you do not pass an additional parameter, and therefore it is impossible to resolve the route. You must pass the requestedPage value and optionally requestedSubPage
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question