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

mbpp's avatar
Level 3

Token mismatch when using Trait RegistersUsers

in my Laravel App to register my users im using the trait "RegistersUsers", and in my controller im overwritting a methdo available that i can use after a user is created, in my case after i user is created i need to create a record with the data previous passed to a table of billing_users.

The method used is:

/**
     * The user has been registered.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  mixed  $user
     * @return mixed
     */
    protected function registered(Request $request, $user)
    {

        // create record for the billing information
        $billing_employer = new BillingEmployer();
        $billing_employer->employer_id = $user->id;
        $billing_employer->country_id =  $user->country;
        $billing_employer->region_id =  $user->region;
        $billing_employer->registered_name =  $user->brand;
        $billing_employer->address =  $user->address;
        $billing_employer->save();

       return $billing_employer;
    }

The only problem is after running this method is giving me a error: TokenMismatchException in VerifyCsrfToken.php line 68:

I had idea that Laravel already handle the token since before creating the record of user already passed this parameter.

Note: For better understanding to do: Controllers/Auth/RegisterController.php and go to use RegistersUsers where is available the method example -> "protected function registered(Request $request, $user)"

What should i do?

0 likes
1 reply
jlrdw's avatar

Why not register a user first, redirect to the other form to be filled out, then do your update.

Please or to participate in this conversation.