new user after ajax validation with laravel
<p>I want to make a record after validation of data sent with ajax. the idea is to run the function CreateNewUser if no errors, but does not store the data in the DB. that will happen this?</p>

<p>Thank you.
    

<pre><code>namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Validator;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use App\Modals\NewUser;

class UserController extends Controller
{
    public function index()
    {
        return view('home');
    }
    public function NewUser(Request $request)
    {
        $validator= Validator::make($request-&gt;all(),[

            'name' =&gt; 'required|max:255',
            'email' =&gt; 'required|email|max:255|unique:users',
            'password' =&gt; 'required|min:8|same:cpassword',
            'cpassword'=&gt; 'required',

        ]);

        if($validator-&gt;fails()){
            return response()-&gt;json([
                'success' =&gt; false,
                'error' =&gt; $validator-&gt;errors()-&gt;toArray()
            ]);


        }else{
            return response()-&gt;json(['success' =&gt; true ]);

            $this-&gt;CreateNewUser($request);
        }

    }

    private function CreateNewUser(Request $requestt){

        $user = new NewUser;
        $user-&gt;name = $requestt-&gt;name;
        $user-&gt;email = $requestt-&gt;email;
        $user-&gt;passwosrd = $requestt-&gt;password;
        $user-&gt;rememberToken = $requestt-&gt;_token;
        $user-&gt;save();
    }


}
</code></pre>

<p>model:</p>

<pre><code>&lt;?php

namespace App\Modals;

use Illuminate\Database\Eloquent\Model;

class NewUser extends Model
{
    protected $table = 'users';
}
</code></pre>

<p>js:</p>

<pre><code>function send(event){

    event.preventDefault();

    $.ajax({


        type: 'post',
        url: userAjax,
        dataType: 'json',
        data: {
            name: $('#name').val(),
            email: $('#correo').val(),
            password: $('#password').val(),
            cpassword: $('#cpassword').val(),
            _token: $('#new-user').attr('data-token')
        },
        beforeSend: function()
        {
            $("#nameError").fadeOut();
            $("#emailError").fadeOut();
            $("#passwordError").fadeOut();
            $("#cpasswordError").fadeOut();

        },

        success: function(data){



           if(!data.success){
               console.log(data);
               if(typeof data.error.name !== 'undefined'){

                   $('#name').css('border-color', 'red');
                   $('#nameError').fadeIn(10, function () {
                       $("#nameError").html(data.error.name);

                   })
               }
               if(typeof data.error.email !== 'undefined'){
                   $('#correo').css('border-color', 'red');
                   $('#emailError').fadeIn(10, function () {
                       $("#emailError").html(data.error.email);

                   })
               }
               if(typeof data.error.password !== 'undefined'){
                   $('#password').css('border-color', 'red');
                   $('#passwordError').fadeIn(10, function () {
                       $("#passwordError").html(data.error.password[0]);


                   })
               }
               if(typeof data.error.cpassword !== 'undefined'){
                   $('#cpassword').css('border-color', 'red');
                   $('#cpasswordError').fadeIn(10, function () {
                       $("#cpasswordError").html(data.error.cpassword);


                   })
               }


            }else{
               console.log(data);
               $('#Register').modal('hide');
               $("#header").replaceWith($('#header'));
            }

        },
        error: function() {}

    });

}
</code></pre>

<p>error:</p>

<pre><code>console.log(data):

jquery.min.js:4 
POST http://localhost:8000/NewUser 500 (Internal Server Error)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
send @ scripts.js:5on
click @ (index):158
</code></pre>