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

Franzis7's avatar

Laravel 8 Role by Registration

For the application I am developing I have 3 roles

• Role 1
• Role 2
• Role 3

from the home page I have 3 links for user registration.

I thought about this approach:

• Link 1 -> Role 1 (Registration form with hidden input role_id)
• Link 2 -> Role 2 (Registration form with hidden input role_id)
• Link 3 -> Role 3 (Registration form with hidden input role_id)

Database

user
role
user_role

for the moment I have only set laravel / ui for authentication.

How can I pass the role value to the registration form via routes?

Thank you all

0 likes
3 replies
CorvS's avatar
CorvS
Best Answer
Level 27

@franzis7 You could simply append the role as query string

<a href="{{ route('register', ['role' => 'role1']) }}">Link 1</a>
<a href="{{ route('register', ['role' => 'role2']) }}">Link 2</a>
<a href="{{ route('register', ['role' => 'role3']) }}">Link 3</a>

and use it as value for a hidden input field for example, which you validate accordingly when the registration form is submitted.

https://laravel.com/docs/8.x/routing#generating-urls-to-named-routes

1 like
Franzis7's avatar

@corvs thank you very much, I did not know this way.

This generates a GET method in the url

register?role=1

is there a way to pass this data via POST method or mask the url?

CorvS's avatar

No, since your register endpoint is a GET route. You could create three different register endpoints (one for each role) instead. That would only be reasonable if you don't have more roles with dedicated registrations in the future tho, depending on the differences in the registration process of course.

Please or to participate in this conversation.