routes.php
<?php Route::get('/', function() { return View::make('layout'); }); Route::get('/api/products', 'HomeController@products'); Route::get('/api/items/total', 'HomeController@total'); Route::get('/api/items', 'HomeController@alist'); Route::post('/api/items', 'HomeController@create'); Route::put('/api/items/{name}', 'HomeController@update'); Route::delete('/api/items/{name}', 'HomeController@del');
app.js
var ShopApp = angular.module('Shop', ['ngRoute']); ShopApp.config(function($routeProvider, $locationProvider) { $routeProvider .when('/', {templateUrl: 'templates/index.php'}) .when('/basket', {templateUrl: 'templates/basket.php'}); // .otherwise({redirectTo: '/'}); // $locationProvider.html5Mode(true); }); ShopApp.factory('Products', function($http) { return { get: function() { return $http.get('/api/products'); } }; }); ShopApp.factory('Total', function($http) { return { get: function() { return $http.get('/api/items/total'); } }; }); ShopApp.factory('Items', function($http) { return { get: function() { return $http.get('/api/items'); }, post: function(product) { return $http.post('/api/items', product); }, put: function(name, changes) { return $http.put('/api/items/'+name, changes); }, del: function(name) { return $http.delete('/api/items/'+name); } }; });
Wklepując ścieżki api z laravela z palca, dostaje się do akcji, natomiast AJAX Angularowy nie działa, napewno źle skonstruowałem ścieżki Angulara, czy ktoś ma pojęcie jak to powinno wyglądać ? Templatki wczytuje poprawnie. W konsoli wypluwa :
GET http://localhost/api/products 404 (Not Found) angular.js:8611
GET http://localhost/api/items 404 (Not Found) angular.js:8611
GET http://localhost/api/items/total 404 (Not Found) angular.js:8611