mardi 5 décembre 2017

Laravel 5 make routing with parameter unique

I am currently using a route with a parameter nameto query the profile of a user in my application.

So for example: /members/johnwill show the profile of John.

You see the problem here, if there are 2 John's then it's gonna be a problem.

I know I could do something like this /members/idsince id is unique but I want the url to look pretty with the user's name and not a random number.

So my question is if there is a way to use the id to make it unique but to display the name in url?

my route:

Route::get('/members/{name}', 'UserController@usersProfile');

My usersProfile method:

/**
 * Returns a users profile.
 *
 * @param string $name
 *
 * @return \Illuminate\Http\Response
 */
public function usersProfile($name)
{
    $profile = $this->userService->getProfile($name);

    if ($profile == null) {
        return redirect('members')->with('status', 'Whoops, looks like that member does not exist (yet).');
    }

    return view('members/profile', ['profile' => $profile]);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire