Laravel Single Page Application Using Angular Js I have created a Laravel Single Page Application using Angular Js 1.3.14 by learning tutorials in the websites.

index.php:

 &lt;body  ng-app = "mainApp"&gt;
   &lt;nav class="navbar navbar-default navbar-static-top" style="background-
   color:orange;"&gt;
     &lt;div class="container"&gt;
       &lt;div class="navbar-header"&gt;
         &lt;a class="navbar-brand prname" href="#home" 
         style="color:red!important;font-weight:bold;font-size:20px;"&gt;
         Company Name
         &lt;/a&gt;
       &lt;/div&gt;
       &lt;div class="collapse navbar-collapse" id="app-navbar-collapse"&gt;
         &lt;ul class="nav navbar-nav"&gt;
           &lt;li class="menustyle home" style="background-color: red;"&gt;&lt;a 
           href="#home"&gt;Home&lt;/a&gt;&lt;/li&gt;
           &lt;li class="menustyle about"&gt;&lt;a href="#aboutus"&gt;About Us&lt;/a&gt;&lt;/li&gt;
           &lt;/li&gt;
         &lt;/ul&gt; 
       &lt;/div&gt;
     &lt;/div&gt;
   &lt;/nav&gt;
    &lt;div class="flex-center position-ref full-height"  style="margin-top:-100px;"&gt;

         &lt;div ng-view&gt;&lt;/div&gt;  

    &lt;/div&gt;
    &lt;script src = "{{ asset('js/main.js') }}"&gt;&lt;/script&gt;
    &lt;script src = "{{ asset('js/controller.js') }}"&gt;&lt;/script&gt;
  &lt;/body&gt;


web.php:

Route::get('/', function () {
   return view('welcome');
});
Route::get('/home', function () {
   return view('home');
});
Route::get('/aboutus', function () {
    return view('aboutus');
});
Route::get('getusers', 'UserController@users');


UserController.php:

class UserController extends Controller
{
    public function users(Request $request)
    {
        $users = DB::table('users')-&gt;get();
        return response()-&gt;json($users);
    }
}


aboutus.blade.php:

&lt;div ng-controller="AddStudentController"&gt;
&lt;table class="table table-bordered"&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Id&lt;/th&gt;
      &lt;th&gt;Name&lt;/th&gt;
      &lt;th&gt;Email&lt;/th&gt;
      &lt;th&gt;Created At&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr ng-repeat = "data in datas"&gt;
      &lt;td&gt;@{{ data.id }}&lt;/td&gt;
      &lt;td&gt;@{{ data.name }}&lt;/td&gt;
      &lt;td&gt;@{{ data.email }}&lt;/td&gt;
      &lt;td&gt;@{{ data.created_at }}&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;


controller.js:

 var mainApp = angular.module("mainApp", ['ngRoute']);
 mainApp.config(['$routeProvider', function($routeProvider) {
    $routeProvider.

    when('/home', {
       templateUrl: '/home',
    }).

    when('/aboutus', {
       templateUrl: '/aboutus',
       controller: 'AddStudentController'
    }).

    when('/services', {
       templateUrl: '/services',
    }).
 }]);    

  mainApp.controller('AddStudentController', function($scope, $http) {
    $http.get('getusers').then( function(response) {
      $scope.datas = response.data;
    });
  });  


The SPA which i have created working correctly, i have developed this project of my own. Is there any thing i want to change or any mistake in routing or any thing in this project.
This code seems okay for the most part - I don't see any major flaws with the code, just a few things that I will critique below.

Despite being spread across quite a few files, this code seems pretty simple. Not that it is by any means wrong, but it is a bit unique to see AngularJS code paired with Laravel code. 


  While Laravel does not dictate which JavaScript or CSS pre-processors you use, it does provide a basic starting point using Bootstrap and Vue that will be helpful for many applications.1


The biggest thing I would critique is the lack of request failure handling. While it may be very unlikely that the AJAX requests to get the list of users would fail, due to the simplicity of the controller method and the fact that if that fails it might also be the case that the page wouldn't have loaded in the first place, it is wise to handle such cases gracefully. Typically when calling .then() on a Promise, the second argument should be supplied for the case when the promise is rejected.

$http.get('getusers').then( function(response) {
  $scope.datas = response.data;
}, 
function(rejectionReason) {
  //handle case when request fails here
});


Or instead of passing the rejection handler as a second argument, it could be passed in a subsequent call to .catch()

Other than that, I would bring up the naming of $scope.datas in the controller:


$http.get('getusers').then( function(response) {
  $scope.datas = response.data;
});



datas is a very generic term. Somebody reading that response could think "After getting the response from getusers, Do we need to abstract the users from response.data? A more appropriate name might just be users:

$http.get('getusers').then( function(response) {
  $scope.users = response.data;
});


Then the markup can be updated accordingly:

 &lt;tr ng-repeat="user in users"&gt;
   &lt;td&gt;@{{ user.id }}&lt;/td&gt;
   &lt;td&gt;@{{ user.name }}&lt;/td&gt;
   &lt;td&gt;@{{ user.email }}&lt;/td&gt;
   &lt;td&gt;@{{ user.created_at }}&lt;/td&gt;
 &lt;/tr&gt;


Other than that, I would suggest conditionally showing the table - only if there are entries in the data array. For that, ng-if and/or ng-show can be used. See the snippet below for an example



var mainApp = angular.module("mainApp", []);
mainApp.controller('AddStudentController', function($scope, $http) {
  $scope.requestSent = false;
  updateUsers = function() {
    $http.get('https://jsonplaceholder.typicode.com/users').then(function(response) {
      $scope.users = response.data;
    }, function(rejectionReason) {
      //display error message?
      $scope.error = rejectionReason;
    })
    .finally(function() {
      $scope.requestSent = true;
    });
  };
  setTimeout(updateUsers, 2000); //wait 2 seconds to simulate network latency
});
&lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"&gt;&lt;/script&gt;
&lt;div ng-app="mainApp"&gt;
 &lt;nav class="navbar navbar-default navbar-static-top" style="background-
   color:orange;"&gt;
     &lt;div class="container"&gt;
       &lt;div class="navbar-header"&gt;
         &lt;a class="navbar-brand prname" href="#home" 
         style="color:red!important;font-weight:bold;font-size:20px;"&gt;
         Company Name
         &lt;/a&gt;
       &lt;/div&gt;
       &lt;div class="collapse navbar-collapse" id="app-navbar-collapse"&gt;
         &lt;ul class="nav navbar-nav"&gt;
           &lt;li class="menustyle home" style="background-color: red;"&gt;&lt;a 
           href="#home"&gt;Home&lt;/a&gt;&lt;/li&gt;
           &lt;li class="menustyle about"&gt;&lt;a href="#aboutus"&gt;About Us&lt;/a&gt;&lt;/li&gt;
           &lt;/li&gt;
         &lt;/ul&gt; 
       &lt;/div&gt;
     &lt;/div&gt;
   &lt;/nav&gt;
    &lt;div class="flex-center position-ref full-height" &gt;

         &lt;div ng-view&gt;&lt;/div&gt;  

    &lt;/div&gt;
  &lt;div ng-controller="AddStudentController"&gt;
    &lt;img src="https://stackoverflow.com/content/img/progress-dots.gif" ng-hide="requestSent"/&gt;
    &lt;table class="table table-bordered" ng-if="users.length" &gt;
      &lt;thead&gt;
        &lt;tr&gt;
          &lt;th&gt;Id&lt;/th&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Email&lt;/th&gt;
          &lt;th&gt;Created At&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
        &lt;tr ng-repeat="user in users"&gt;
          &lt;td&gt;@{{ user.id }}&lt;/td&gt;
          &lt;td&gt;@{{ user.name }}&lt;/td&gt;
          &lt;td&gt;@{{ user.email }}&lt;/td&gt;
          &lt;td&gt;@{{ user.created_at }}&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;div ng-bind="error"&gt;&lt;/div&gt;
  &lt;/div&gt;




1https://laravel.com/docs/5.7/frontend