1

I am building a social networking application using Laravel 5, and I am slightly confused about the structure of the URLs.

Using a previous Stack Overflow post from another member, I have managed to grasp the basics (profiling, account, etc). Here is what I have so far:

http://myapp.com/account/create

http://myapp.com/account/login
http://myapp.com/account/logout

http://myapp.com/account/verify
http://myapp.com/account/verify/{token}
http://myapp.com/account/settings

http://myapp.com/profile/FooMan

And that's all well and good (at least I think so - any tips are welcome), but how do I go about creating a URL structure for things such as friends? I get that you could have:

http://myapp.com/profile/FooMan/friends

But to me, that seems ugly. And if I wanted to add a "/add" route to the friends, how would I go about that also? Thank you in advance!

P.S. On some of the pages, such as "login" and "create" I use the route::get() to display the form, and route::post() to submit the details to the controller. Is this bad practice?

6
  • Why does it look ugly? I think it looks good? Or is FooMan the current user and you want profile/my-friends ? Commented Apr 11, 2015 at 14:30
  • I think it's a bit of both. For example, when a user wants to add a friend, which url would that be? profile/FooMan2/add? Commented Apr 11, 2015 at 14:33
  • Hmm I am not really seeing the issue? You could drop profile all together, and just have domain.com/fooman2 for someone elses profile, and domain.com/friends for current users connections. This is pretty standard just navigate around twitter and facebook. Commented Apr 11, 2015 at 14:37
  • I thought about that, but then what about when we're creating new pages and it overlaps with somebody's username? Commented Apr 11, 2015 at 14:38
  • 1
    You need a list of reserved words before going live - you wouldn't be allowed to create a username friends, create, unfollow etc much like reserved words in a programming language. I am sure twitter doesn't allow you to signup with the account name followers. You will only have at most 10 or 20 root route actions so its not hard to add to your validation Commented Apr 11, 2015 at 14:42

1 Answer 1

1

I think following a standard system such as facebook or twitter would help with your routing approach.

To avoid lengthy urls, you can route directly to a profile via their user name, using a route such as:

Route::get('{username}', ...);
Route::get('{username}/friends', ...);
// etc

// Current user
Route::get('friends', ...);

Now, there will be occasions where a username may conflict with a core action such as domain.com/friends or domain.com/login. Establish a list of core actions and restrict users from signing up with those keywords. This is simple by using laravel's not in validation.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for your help, this has been most useful. I shall use this approach!
Cool no problem. Goodluck

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.