You need to distinguish between the routes of your Laravel application and the routes of your Angular application.
Define a route to display Angular application
Route::get('/{js_route}', function() {
return view('application');
})->where('js_route', '(.*)');
This route allows the slash to do your routing with ngRoute, and it should be the last one specified in yours routes.php.
It will simply display the template that will be used to display your real Angular application.
// views/application.blade.php
<html>
<body>
<div class="container">
<div ng-view></div>
</div>
</body>
</html>
Angular
ngRoute .
// public/js/src/app.js
$routeProvider
.when('/', {
templateUrl: 'Default/index.html', // A simple HTML template
});
// ...
API Laravel
XHR Laravel Angular.
(.. GET, POST) /.
class FooController extends \BaseController {
public function index()
{
return Response::json(Foo::get());
}
}
Route::get('/api/foo', 'FooController@index')
/
(function (app) {
function FooService($http, $q) {
this.getFoos = function() {
return $http.get('/api/foo');
};
}
app.service('Foo', FooService);
})(angular.module('yourApp'));
, larvel . //public/js/src/app.js
function MainCtrl($scope, $http) {
$scope.listFoo = function() {
$http.getFoos()
.then(function(response) {
$scope.foos = response.data;
}, function(error) {
console.log(error);
});
};
}
app.controller('MainController', MainCtrl);
javascript Laravel.