I have created a Laravel Single Page Application using Angular Js 1.3.14 by learning tutorials in the websites.
index.php:
<body ng-app = "mainApp">
<nav class="navbar navbar-default navbar-static-top" style="background-
color:orange;">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand prname" href="#home"
style="color:red!important;font-weight:bold;font-size:20px;">
Company Name
</a>
</div>
<div class="collapse navbar-collapse" id="app-navbar-collapse">
<ul class="nav navbar-nav">
<li class="menustyle home" style="background-color: red;"><a
href="#home">Home</a></li>
<li class="menustyle about"><a href="#aboutus">About Us</a></li>
</li>
</ul>
</div>
</div>
</nav>
<div class="flex-center position-ref full-height" style="margin-top:-100px;">
<div ng-view></div>
</div>
<script src = "{{ asset('js/main.js') }}"></script>
<script src = "{{ asset('js/controller.js') }}"></script>
</body>
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')->get();
return response()->json($users);
}
}
aboutus.blade.php:
<div ng-controller="AddStudentController">
<table class="table table-bordered">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Created At</th>
</tr>
</thead>
<tbody>
<tr ng-repeat = "data in datas">
<td>@{{ data.id }}</td>
<td>@{{ data.name }}</td>
<td>@{{ data.email }}</td>
<td>@{{ data.created_at }}</td>
</tr>
</tbody>
</table>
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.