laravel route method code example

Example 1: call laravel route js

function confirmDelete(id){
    let url = "{{ route('getDeleteRequest', ':id') }}";
    url = url.replace(':id', id);
    document.location.href=url;
}

Example 2: laravel get route

Route::get('foo', function () {
    return 'Hello World';
});

Example 3: laravel route

# Using Request
Route::get('user/{name}', function (Request $request) {
    return $request->route('name');
});

Example 4: laravel route

Route::get('user/{id}', function ($id) {
    return 'User '.$id;
});

Example 5: routing in laravel

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

Example 6: prefix laravel route

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