How to: AngularJS http GET request to Laravel CRUD resource controller -
i have been trying response laravel resource controller through http request angularjs. please let me know i'm doing wrong. console.log() not show anything.
web.php file has following route
route::resource('comments', 'commentscontroller');
i have laravel resource(crud) controller named commentscontroller has function.
public function show(comment $comment) { //show comement $articlecomments = db::table('comments')->where('id', $comment->articleid); if (!$articlecomments->isempty()) { //return json response return response()->json($articlecomments); } else { return response()->json(['status' => 'not found!']); } }
this laravel route list looks comments
laravel route:list comments controller
i want use angularjs http request retrieve comments article. angularjs code.
var app = angular.module('myapp', []); app.controller('myctrl', function($scope, $http) { $scope.loadcomments = function(id){ $http.get("comments",{ params: { 'articleid': id }}) .then(function(response) { //first function handles success console.log(response.data) }, function(response) { //second function handles error console.log(response.data) }); } });
i have included csrf protection tag well
<meta name="csrf-token" content="{{ csrf_token() }}">
my html button initiated loadcomments
<button type="button" id="getarticleid" class="btn btn-default" aria-label="comment button" ng-click="loadcomments({{$key->id}})">
my response looks
Comments
Post a Comment