Laracasts User Profile URL Structure (/@Username)

Published 1 year ago by Tipoff

What's the best practice for setting up user profiles with a URL structure of /@Username like that used here on Laracasts or on Medium? In Laravel, what would I insert in the route file?

On a side note, what are the SEO implications of using the @ sign in a URL? Are there any negative consequences for search engine readability?

Best Answer (As Selected By Tipoff)
bunnypro

you can set the route like

Route::get('/@{username}', function ($username) {});
bunnypro

you can set the route like

Route::get('/@{username}', function ($username) {});
odayo
odayo
1 year ago (2,570 XP)

How would you reference it in the view link?

Cronix
Cronix
1 year ago (737,880 XP)

Give the route a name and use the route('name') in your links.

Route::get('/@{username}', '[email protected]')->name('username');
<a href="{{ route('username', ['username' => 'bob']) }}">@Bob's Profile</a>

Or just manually without a named route

<a href="/@{{ $user->name }}">@{{$user-name}}'s Profile</a>

https://laravel.com/docs/5.5/routing#named-routes

Please sign in or create an account to participate in this conversation.