Named Route and Routes Group Laravel 11

 // Below is Named Routes declaration:

Route::get("/test", function () {
    return view("about");
})->name("aboutus");

Route::redirect("/about", "/test");

Route::get("/posttest", function () {
    return view("post");
})->name("mypost");

Route::redirect("/post", "/posttest");

Route::get("/thispost", function () {
    return view("firstpost");
})->name("firstpostishere");


// Making Routes Group as shown below :
Route::prefix("page")->group(function () {
    Route::get("/about", function () {
        return "<h1>About Page</h1>";
    });

    Route::get("/gallery", function () {
        return "<h1>Gallery Page</h1>";
    });

    Route::get("/post/firstpost", function () {
        return "<h1>First Post Page</h1>";
    });
});

// If any page is not present then default error 404 will not show but fallback function will call instead of "404 | NOT FOUND".
Route::fallback(function () {
    return "<h1>Page Not Found.</h1>";
});


Comments

Popular posts from this blog

Eloquent Many to Many Relationship Tutorial in Laravel 11

Eloquent with JSON Data Columns Tutorial in Laravel 11

Blade Template Tutorial Three Template Inheritance in Laravel 11