title: Laravel distincted script mechanics call
body: <p>I am pretty much beginner in programming. Since few weeks I've been using Laravel framework. So far, I was using ajax and redirects to reach the functions in controller through Routes. Someone told me that it is wrong to use redirects and so many ajaxes in Views. So how do I call these functions and all mechanics in a proper way then? I read the documentation not for the first time but I still dont get it. Could someone explain it to me a little bit please?</p>
  
  <p>This is an example how do I use views with controller. 
  viewfile.blade.php:</p>
  
  <pre><code>$.ajax({
      type: "POST",
      url: "/ineedthisfunction",
      data: {
  
      },
  
          success: function(msg) {
              alert(msg);
          },
  
          error: function(error) {
              alert('error');
          }
  });
  </code></pre>
  
  <p>routes:</p>
  
  <pre><code>    Route::post('/ineedthisfunction', 'Controller@thisfunction');
  </code></pre>
  
  <p>controller:</p>
  
  <pre><code>public function thisfunction(){
  return "some returned value from script";
  }
  </code></pre>
  
  <p>I am doing this everytime I need to use any php code. Or I am writing it inside of views. They tell me both are wrong. What do I do then?</p>
  
  <p>Sometimes instead of ajax i just do: "header("location:/ineedthisfunction"); But i think it is horrible idea to.</p>