When entering the url, domain.com/floorplans, I would like the FloorplanController.php to return all floorplans to an angular controller and also return the view.
Here is FloorplanController@index:
public function index()
{
$floorplans = Floorplan::all();
return view('floorplans.index', compact('floorplans'));
}
Here is my Angular controller:
angular
.module('myApp', [])
.controller('FloorplanController', function($scope, $http) {
$http.get('/floorplan').success(function(floorplans) {
$scope.floorplans = floorplans;
});
});
The above doesn't work as $scope.floorplans = floorplans; is always undefined.
If I create two separate routes in my routes.php file, I can get it to work, but that seems very sloppy.
Route::get('/', function()
{
return view('floorplans.index');
});
Route::get('test', function()
{
return Floorplan::all();
});
What is the proper syntax to return a view with an object so that the object is picked up by my Angular controller?