Angular http post不与Laravel合作

时间:2017-04-18 05:20:40

标签: php angularjs laravel http post

我的laravel帖子有效。用邮递员测试并进入数据库。一切正常,但稍微改变现在给我一个500(内部服务器错误)。

Laravel控制器从模型中调用...我的 EventController.php(laravel)

    public function store(Request $request) {
    $event = new Event();
    $event->event_title = $request->input('event_title');
    $event->event_description = $request->input('event_description');
    $event->event_location = $request->input('event_location');
    $event->event_date = $request->input('event_date');
    $event->event_time = $request->input('event_time');
    $event->save();

    //return response()->json(['event'=>$event, 'user'=>$user], 201);
    //return 'Event record successfully created';
  }

Eventform.html(angularjs)

<div ng-controller="FormController">
  <ion-header-bar classic="bar-dark" id="formHead">
   <h1 class="title">New Event</h1>
   </ion-header-bar>
   <ion-view title="Event Form">
 <ion-content padding="true" class="has-header">
 <form id="eventForm" class="list" role="form">
  <label class="item item-input item-stacked-label">
    <span class="input-label">Event Name</span>
    <input type="text" ng-model="newEvent.event_title" required="true" 
    placeholder="Gregs' Birthday!">
  </label>
  <label class="item item-input item-stacked-label">
    <span class="input-label">Description</span>
    <input type="text" ng-model="newEvent.event_description" 
   required="true" placeholder="Celebrate his 22nd year.">
  </label>
  <label class="item item-input item-stacked-label">
    <span class="input-label">Location</span>
    <input type="text" ng-model="newEvent.event_location" 
    required="true" placeholder="123 Maple Lane">
  </label>
  <label class="item item-input item-stacked-label">
    <span class="input-label">Date</span>
    <input type="date" ng-model="newEvent.event_date" required="true" 
     format="yyyy-mm-dd">
  </label>
  <label class="item item-input item-stacked-label">
    <span class="input-label">Time</span>
    <input type="time" ng-model="newEvent.event_time" required="true">
  </label>
    <button type="button" class="button button-full" id="button-save" 
     ng-click="save()">Save</button>
</form>

</ion-content>

</ion-view>
   </div>

event.js(angular post method)

 ThesisApp.controller('FormController', ['$scope', '$http',  
 '$location', function($scope, $http,   $location) {
  $scope.newEvent = {};
  $scope.save = function() {
  $scope.newEvent= angular.copy(event);
  console.log("yes I'm being called");
   console.log($scope.newEvent);

$http.post('http://thesis-app.dev/events/posts', $scope.newEvent, {headers: {'X-Requested-With': 'XMLHttpRequest'}}).success(function(response) {
      console.log(response);
    })
    .error(function(response) {
    console.log(response);
      });
   }

}]);

0 个答案:

没有答案