Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ElpsySec's avatar

Getting correct url with resource in routes.

I have a resource for home which is my home and then i have a resource. When i go to /home/7/show by directing to home.show after login where 7 is the user id, the actual route is blog.app/home/%7Bhome%7D.

Is this laravel being awesome and hiding my database ids in the url or is there something fishy that i need to fix?

A couple of other questions while i have your attention.

How would i change the {home} paramter in the route resource. Right now the list looks something like:

/home

/home/{home}

/home/{home}/edit

/home/create

etc

Let's say i wanted it to say {user} instead.

As well, what if I didn't want the paramter to represent id? What if I wanted it to represent user_type or something.

Sorry for obvious questions, I'm scouring the documentation looking for the answers but this forum is always so helpful and friendly I thought I'd ask. Thanks

0 likes
10 replies
mstnorris's avatar

You're not passing in the Id. Please show your routes.php file.

RomainLanz's avatar

You are restricted if you use the resource() helper. I recommend you to write all routes by your hand.

Also, if you want to use a slug instead of an ID in your URL I recommend you the Eloquent Sluggable package.

ElpsySec's avatar

@mstnorris

Route::resource('home', 'HomeController');
Route::resource('home.user', 'UserController');

this yields http://blog.app/home/%7Bhome%7D when redirected after login to route('home.show')

Home is meant to control the user homepage and the home/{id}/user is meant to control some meta stuff about the user. Just realy worried about the current url shown

RomainLanz's avatar

@OkabeOkabe You need to pass an ID to your view home.show.

EDIT: Seems what you want to do you should probably redesign your application.

ElpsySec's avatar

Show looks like

public function show($id)
    {
        return view('pages.home);
    }

My redirect looks like


 if (Auth::attempt($credentials, $request->has('remember'))) {
     $this->redirectPath = route('home.show');
    return redirect()->intended($this->redirectPath());
 }
            

I tried adding


 if (Auth::attempt($credentials, $request->has('remember'))) {
     $this->redirectPath = route('home.show');
    return redirect()->intended($this->redirectPath()->with('id', Auth::user()->id);
});
```

But this didn't change the url.
```
ElpsySec's avatar

@RomainLanz I tried passing ->with('id', Auth::user()->id) in the redirect but it didn't work. Can you elaborate on how to pass the id in the resource please?

Do i need to define $id in the show method?

RomainLanz's avatar
return redirect()->route('home.show', [auth()->id]);

Please or to participate in this conversation.