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

Narares's avatar

How to custom the RegisterController to save multiple data when user selected

Dear all,

I am a newbie in Laravel and I need your help.

I'm using the Laravel 7. I have 3 tables in my database.

  1. User to save the registered users
  2. Categories to show in the front-end that I provided for them to choose (multiple)
  3. Vendor_Cat that I collecting the user_id and category_id after the user registered

Here are my Models


public function users(){
        return $this->BelongsToMany(User::class);
    }
public function categories(){
        return $this->BelongsToMany(Categories::class);
    }

And this is the Laravel RegisterController

   protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
            'tel' => $data['tel'],
            'lineid'=> isset($data['lineid']) ? $data['lineid'] : null,
        ]);

If I want to save the category Ids that I use @foreach to show in the Register Form after the users selected. What should I do?

Here is the explanation image https://ibb.co/vQpfxxH

p.s. sorry for my bad English.

0 likes
3 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@narares can you use 3 ` before and after your code so that your code will be readable.

6 likes
Narares's avatar

Oh! sorry, I have tried but I can't do it.

5 likes

Please or to participate in this conversation.