Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
Laravel

Routing Through Buttons and Anchor Tags in Laravel

Generate correct URLs in Blade using route() helpers for links, buttons, and forms.

Routing Through Buttons and Anchor Tags in Laravel — a practical guide to Laravel named routes links with clear examples you can reuse in real projects.

Laravel Tutorial Series (11/27). Prefer one page? Read the complete Laravel tutorial (all 27 topics).

Short description

Use named routes so links stay correct even if URL paths change later.

Define named routes

Route::get('/posts', [PostController::class, 'index'])->name('posts.index');
Route::get('/posts/{post}', [PostController::class, 'show'])->name('posts.show');
Route::delete('/posts/{post}', [PostController::class, 'destroy'])->name('posts.destroy');

Anchor tags

<a href="{{ route('posts.index') }}">All posts</a>
<a href="{{ route('posts.show', $post) }}">{{ $post->title }}</a>

Button that submits a form (DELETE example)

<form action="{{ route('posts.destroy', $post) }}" method="POST" onsubmit="return confirm('Delete?')">
    @csrf
    @method('DELETE')
    <button type="submit">Delete</button>
</form>

Button linking with JavaScript-free navigation

<a class="btn" href="{{ route('posts.create') }}">Create post</a>

Leave a reply

Your email address will not be published. Required fields are marked *