title: How do I post a form in laravel 5 using ajax?
body: <p>I'm having a ton of trouble learning how to make an ajax post in laravel.  I want to be able to show errors using jquery after validation but I have no idea how to access the object sent to my controller; so I dont even know what to 'return' in the controller.  Can someone please walk me through this?</p>
  
  <p>This is a part of my view </p>
  
  <pre><code>&lt;meta name="_token" content="{{ csrf_token() }}" /&gt;            
  &lt;div class='row'&gt;
          {!! Form::open(['url'=&gt;'register','id'=&gt;'sign-up','class'=&gt;'col-md-6 col-md-push-4 form-horizontal'])!!}
  
              &lt;div class='form-group'&gt;
                  {!! Form::label('first_name', 'First Name:',['class'=&gt;'col-xs-12 col-md-3']) !!}
                  &lt;div class= 'col-xs-12 col-md-6'&gt;
                      {!! Form::text('first_name', null, ['class' =&gt; 'form-control'])!!}
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class='form-group'&gt;
                  {!! Form::label('last_name', 'Last Name:',['class'=&gt;'col-xs-12 col-md-3']) !!}
                  &lt;div class= 'col-xs-12 col-md-6'&gt;
                      {!! Form::text('last_name', null, ['class' =&gt; 'form-control'])!!}
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class='form-group'&gt;
                  {!! Form::label('email', 'Email Address:',['class'=&gt;'col-xs-12 col-md-3']) !!}
                  &lt;div class= 'col-xs-12 col-md-6 '&gt;
                      {!! Form::text('email', null, ['class' =&gt; 'form-control'])!!}
      &lt;div class='form-group'&gt;
              {!! Form::label('password', 'Password:',['class'=&gt;'col-xs-12 col-md-3']) !!}
                  &lt;div class= 'col-xs-12 col-md-6'&gt;
                      {!! Form::password('password', null, ['class' =&gt; 'form-control'])!!}
                  &lt;/div&gt;
              &lt;/div&gt;
  
                      &lt;div class='form-group'&gt;
              {!! Form::label('password_confirmation', 'Confirm Password:',['class'=&gt;'col-xs-12 col-md-3']) !!}
                  &lt;div class= 'col-xs-12 col-md-6'&gt;
                      {!! Form::password('password_confirmation', null, ['class' =&gt; 'form-control'])!!}
                  &lt;/div&gt;
              &lt;/div&gt;
                      &lt;/div&gt;  &lt;div class='btn btn-small'&gt;
                  {!! Form::submit('Join Us!',['class'=&gt;'btn btn-success btn-sm form-control'])!!}
              &lt;/div&gt;
  
          {!! Form::close() !!}
          &lt;/div&gt;
  </code></pre>
  
  <p>.js file:</p>
  
  <pre><code>$(function(){
  
  $('#sign-up').on('submit',function(e){
      $.ajaxSetup({
          header:$('meta[name="_token"]').attr('content')
      })
      e.preventDefault(e);
  
          $.ajax({
  
          type:"POST",
          url:'/register',
          data:$(this).serialize(),
          dataType: 'json',
          success: function(data){
              console.log(data);
          },
          error: function(data){
  
          }
      })
      });
  });
  </code></pre>
  
  <p>controller: </p>
  
  <pre><code>&lt;?php 
  
  namespace App\Http\Controllers;
  
  use App\Http\Requests\CreateRegisterRequest;
  use App\Http\Controllers\Controller;
  use App\User;
  use Illuminate\HttpResponse;
  use Input;
  class UserController extends Controller
  {
  
      public function create(CreateRegisterRequest $request)
      {
  
      }
  
      public function show()
      {
          return view('user.profile');
      }
  
  }
  </code></pre>
  
  <p>Form Request:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Requests;
  
  use App\Http\Requests\Request;
  
  class CreateRegisterRequest extends Request
  {
      public function authorize()
      {
          return true;
      }
  public function rules()
      {
          return [
              'first_name' =&gt;'required',
              'last_name'=&gt;'required',
              'url'=&gt;'url',
              'description',
              'email'=&gt;'unique:users,email|email',
              'password'=&gt;'min:6|confirmed',
              'password_confirmation'=&gt;'min:6'
  
  
          ];
      }
  }
  </code></pre>