Get the solution ↓↓↓
You need to do two things.
I am assuming you are using the default auth scaffolding. If you look into theRegistersUsers trait on yourRegistrationController you will see that laravel is using theshowRegistrationForm method to display the registration form. In yourRegistrationController class you need to override this method to display your custom registration form. You can do this like so:
/**
* Show the application registration form.
*
* @return \Illuminate\View\View
*/
public function showRegistrationForm()
{
$departements = Departement::all();
return view('auth.register', [ 'departements' => $departments ]);
}
Secondly, you will need to customize the blade file located at./resources/views/auth/register.blade.php. Since you only provided the snippet for the dropdown, I will inline it into a defaultauth.register blade file here.
<form method="POST" action="/auth/register">
{!! csrf_field() !!}
<div>
Name
<input type="text" name="name" value="{{ old('name') }}">
</div>
<div>
Email
<input type="email" name="email" value="{{ old('email') }}">
</div>
<div>
Password
<input type="password" name="password">
</div>
<div>
Confirm Password
<input type="password" name="password_confirmation">
</div>
<div class="form-group-row">
<label for="departements" class="col-md-4 control-label text-md-right">Départements :</label>
<div class="col-md-6">
<select name="departements" id="departements" class="form-control">
@foreach($departements as $departement)
<option value="{{ $departement ->id }}">{{ $departement ->name }}</option>
@endforeach
</select>
</div>
</div>
<div>
<button type="submit">Register</button>
</div>
</form>
Did you define $departements from the loop in the view or pass it from controller? If not, assuming you have user passed in the view try this.
@foreach($user->departements() as $departement)
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.