Hello. There is a method that is responsible for registration: enter image description here

The highlighted line calls the method: enter image description here

Here is the root responsible for this: enter image description here

And here is the controller: enter image description here

In fact, after registering a user, the redirect to / api / role should add data to the roles table, but this does not happen, only data is added to the users table, nothing is added to the roles. in the console just undefined: enter image description here

How to fix?

    1 answer 1

    First of all, it’s impossible to redirect so with an Ajax request, you have to redirect to JS when responding from the server. Second, when creating a new instance of the class, we don’t put brackets, just new Role; Third, the $ auth = $ request-> all () line is superfluous. Everything is much simpler:

    $role = new Role; $role->email = $request->email; $role->role_name = $request->role_name; $role->save(); 

    And you can even easier:

     Role::firstOrCreate(['email' => $request->email,'role_name' => $request->role_name]); 
    • This is where I didn’t understand something: it’s редеректить так при аякс запросе нельзя, ты должен сделать редирект на JS при ответе с сервера . - Eugene
    • @ Eugene In the controller method you have to send the answer that everything is OK (HTTP 200). And in the then () function of the role method in Vue, make a redirect. location.href = 'http: // ...'; - NONAME pm