title: Laravel 4: Save data into database using ajax from a bootstrap modal
body: <p>I'm upgrading an old php project into a laravel 4 project. I have a function that adds company data using ajax from a bootstrap modal. But this code is not suitable for my current laravel project because i have used mysql_connect and mysql_select_db on this file. I have tested it and it still works but i want to use named routes like companies.store. I'm currently using restful routing for the project and it works perfectly. Here is my old code combined with the current laravel project, which actually works perfectly by the way. </p>
  
  <p>create.blade.php</p>
  
  <pre><code>function addNewCompany(){
          var ajaxRequest;  
  
          try{
  
              ajaxRequest = new XMLHttpRequest();
          } catch (e){
  
              try{
                  ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
              } catch (e) {
                  try{
                      ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                  } catch (e){
  
                      alert("Your browser doesn't support ajax!");
                      return false;
                  }
              }
          }
  
          ajaxRequest.onreadystatechange = function(){
              if(ajaxRequest.readyState == 4){    
                  //txtMessage is used to show message returned from the ajaxRequest
                  document.getElementById('txtMessage').value = ajaxRequest.responseText;
              }
          }           
  
          var companyName = document.getElementById('txtCompanyName').value;          
  
          ajaxRequest.open('POST', '{{ URL::asset("assets/query/saveCompany.php") }}');
          ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
          ajaxRequest.send("companyName=" + companyName);
  
  
      }
  </code></pre>
  
  <p>saveCompany.php //which i placed inside the public/assets/query folder</p>
  
  <pre><code>&lt;?php    
  
  $companyName = $_POST["companyName"];
  
    $con=mysql_connect("localhost","root","");
    mysql_select_db("dbname", $con);
  
    $sql = "INSERT INTO `companies` (`companyName`) 
      VALUES ('$companyName')";
  
    $result = mysql_query($sql, $con);
    if($result)
    {
      echo "Company added successfully";
    }
    else
    {
      echo mysql_error();
    }
  ?&gt;
  </code></pre>
  
  <p>So instead of sending the ajax request to a saveCompany.php file, how can i use resourceful routing by sending the request to say, company.store.</p>