title: How to save file in folder using AngularJS service and Laravel Controller
body: <p>I am not getting how can I send file form service to laravel controller and store it in a folder.</p>
  
  <p>Here is view and controller (Angularjs Front end)
  <strong>View</strong></p>
  
  <pre><code>&lt;html&gt;
  
   &lt;head&gt;
    &lt;script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"&gt;&lt;/script&gt;
   &lt;/head&gt;
  
    &lt;body ng-app = "myApp"&gt;
  
    &lt;div ng-controller = "myCtrl"&gt;
      &lt;form  enctype="multipart/form-data"&gt;
       &lt;input type = "file" file-model = "myFile"/&gt;
       &lt;button ng-click = "uploadFile()"&gt;upload me&lt;/button&gt;
       &lt;/form&gt;
    &lt;/div&gt;
  
   ** controller**
    &lt;script&gt;
       var myApp = angular.module('myApp', []);
  
       myApp.directive('fileModel', ['$parse', function ($parse) {
          return {
             restrict: 'A',
             link: function(scope, element, attrs) {
                var model = $parse(attrs.fileModel);
                var modelSetter = model.assign;
  
                element.bind('change', function(){
                   scope.$apply(function(){
                      modelSetter(scope, element[0].files[0]);
                   });
                });
             }
          };
       }]);
  
       myApp.service('fileUpload', ['$http', function ($http) {
          this.uploadFileToUrl = function(file, uploadUrl){
             var fd = {'file' : file}
             var file = {
              'file' : file
             }
              console.log(uploadUrl, fd)
              $http.post("http://myipaddress/practice/upload/blog/public/index.php/uploadavtar",uploadUrl, fd)
              .then(function(response) {
              console.log(response.data)
              });
          }
       }]);
  
       myApp.controller('myCtrl', ['$scope', 'fileUpload', function($scope, fileUpload){
          $scope.uploadFile = function(){
             var file = $scope.myFile;
  
             console.log('file is ' );
             console.dir(file);
  
             var uploadUrl = "/fileUpload";
             fileUpload.uploadFileToUrl(file, uploadUrl);
          };
       }]);
  
    &lt;/script&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p><strong>Laravel Controller</strong></p>
  
  <pre><code>&lt;?php
  
   namespace App\Http\Controllers;
  
   use Illuminate\Http\Request;
  
   use App\Http\Requests; 
   use Illuminate\Support\Facades\Input;
  
  class UsersController extends Controller
  {
  public function uploadavtar(Request $request){
  
  
       $extension = Input::file('file')-&gt;getClientOriginalExtension();
       $filename = rand(11111111, 99999999). '.' . $extension;
       Input::file('file')-&gt;move(
         '192.168.2.68/practice/upload/public/files/uploads/', $filename
       );
  
        $fullPath = 'myipaddress/practice/upload' . $filename;
  
       return  $fullPath ;
  
  }
   }
  </code></pre>
  
  <p>I checcked the above larave controller through postman its working fine only problem is its not storing the file. And if I do same from submit button its showing error of  </p>
  
  <pre><code>'Call to a member function getClientOriginalExtension() on a non-object
  '
  </code></pre>
  
  <p>How to solve this both issues.
  1. Sending file form service to laravel controller 
  2. storing it in defined path.</p>