add route laravel code example

Example 1: named route with parameter laravel

Route::get('/menu/{category}/{product}/{item}', ['as' => 'named.route' , 'uses' => 'MenuController@listItem']);

// to get the actual linke
route('named.route', ['category' => $category->id, 'product' => $product->id, 'item' => $item->id]);

Example 2: laraval routing

Route::redirect('/here', '/there', 301);

Example 3: laraval routing

use App\Http\Controllers\UserController;
use App\Models\User;

// Route definition...
Route::get('/users/{user}', [UserController::class, 'show']);

// Controller method definition...
public function show(User $user)
{
    return view('user.profile', ['user' => $user]);
}

Example 4: laravel route

Route::view('/welcome', 'welcome');

Route::view('/welcome', 'welcome', ['name' => 'Taylor']);

Example 5: laravel route

Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) {
    //
});

Tags:

Php Example