Support the ongoing development of Laravel.io →
posted 10 years ago
Views

Hi all, I am creating an app that when the user logs in, the user id is in the url like "domain.com/1234567/somepage". In my routes I am able to grab the id like so

Route::group(array('prefix' => '{account_id}','before' => 'auth'), function()
	{
    Route::resource('somepage', 'SomepageController');
});

But I don't know how to fix or modify something like {{ URL::to('somepage/create') }} so that it creates the URL like "domain.com/1234567/somepage/create" instead of "domain.com/somepage/create"

Can someone give me some ideas?

John

Last updated 3 years ago.
0

Since you are using the "before" filter for that set of routes you could use

 URL::to(Auth::user()->id.'/somepage/create');

You could also use named routes and do

 URL::route("name_of_your_route")->with(array('user_id' => Auth::user()->id));

Which ever you prefer my point is that you could get the current user's id through

 Auth::user()->attribute;
Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

otherjohn otherjohn Joined 19 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.