HenryDev HenryDev - 1 year ago 41
PHP Question

Ho to set the right URL in Laravel

I'm trying to go to a specific URL based on the User's id. When I'm on the home page I can see user's email as well as user's id just fine by doing this:

<div class="panel-body">
Hola <strong>{{ Auth::user()->name }}</strong><br/> Welcome!
{{Auth::user()->email}} // tester@gmail.com
{{Auth::user()->id}} // 15

But after clicking on this Link:

<a href="{{ url('/edit-user/Auth::user()->id') }}">Edit User</a>

I would like to go to:

But when I click on that link I get this link:


Can anyone tell me what I'm doing wrong please?

Here's my routes.php

Route::get('edit-user/{id}', 'HomeController@edit');

Here's my HomeController:

public function edit($id)
$students = Student::where("id", $id)->first();
return view('edit-user', compact('students'));

Answer Source

The single quotes is breaking it. You need to use this:

       <a href="{{ url('/edit-user/' . Auth::user()->id) }}">Edit User</a>