Create user in users table and insert data into second table with one form in Laravel Relationships I'm trying  to create a user while adding data to a second table via one form:

users table:

Schema::create('users', function (Blueprint $table) {
        $table-&gt;id();
        $table-&gt;string('email')-&gt;unique();
        $table-&gt;timestamp('email_verified_at')-&gt;nullable();
        $table-&gt;string('password');
        $table-&gt;rememberToken();
        $table-&gt;timestamps();
    });


info table:

Schema::create('infos', function (Blueprint $table) {
        $table-&gt;id();
        $table-&gt;string('fname');
        $table-&gt;string('lname');
        $table-&gt;string('dateofbirth');
        $table-&gt;string('phonenumber')
        $table-&gt;timestamps();
    });


info_user table:

Schema::create('info_user', function (Blueprint $table) {
        $table-&gt;id();
        $table-&gt;unsignedBigInteger('user_id');
        $table-&gt;unsignedBigInteger('info_id');
        $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users')-&gt;onUpdate('cascade')-&gt;onDelete('cascade');
        $table-&gt;foreign('info_id')-&gt;references('id')-&gt;on('infos')-&gt;onUpdate('cascade')-&gt;onDelete('cascade');
        $table-&gt;timestamps();
    });


User.php Model

public function infos() {
    return $this-&gt;belongsToMany(Info::class)-&gt;withTimestamps();;
}


Info.php Model

public function users() {
    return $this-&gt;belongsToMany(User::class)-&gt;withTimestamps();
}


And my attempt at InfoController

public function store(Info $info, User $user, Request $request)
{

        User::create([
            'email' =&gt; $request-&gt;email,
            'password' =&gt; Hash::make($request-&gt;password),
        ]);

        $data = new Info;
        $data-&gt;fname = $request-&gt;fname;
        $data-&gt;lname = $request-&gt;lname;
        $data-&gt;dateofbirth = $request-&gt;dateofbirth;
        $data-&gt;phonenumber = $request-&gt;phonenumber;

        $data-&gt;save();

    return redirect('/');
}


I'm trying to figure out how to register a user while adding info to the second table so they have a common info_user table.

I think I succeeded, but only if it is right and especially safe.

public function store(Info $info, User $user, Request $request)
{
        $user = User::create([
            'email' =&gt; $request-&gt;email,
            'password' =&gt; Hash::make($request-&gt;password),
        ]);

        $data = new Loan;

        $data-&gt;fname = $request-&gt;fname;
        $data-&gt;lname = $request-&gt;lname;
        $data-&gt;dateofbirth = $request-&gt;dateofbirth;
        $data-&gt;phonenumber = $request-&gt;phonenumber;

        $data-&gt;save();

        $user-&gt;infos()-&gt;attach($data);

    return redirect('/');
}
It's a correct way to do it like this.
Few suggestions:

Add validation before creating user. You don't want to fail on save for duplicate user email. For better UX if you can it's a good idea to do it even before form submit (with ajax request when email field is changed).

If your app has more user related things like user profile, user control panel I will suggest you to auto login user after form submit. Just before redirect() add Auth::login($user)