title: How to handle JSON.stringify data in Laravel
body: <p>I am trying to catch data from Ajax in Laravel controller to save it. But I keep getting error as seen image below. What am I doing wrong here?</p>
  
  <p>Laravel Controller@ajaxstore</p>
  
  <pre><code>public function ajaxstore(Request $request)
  {
  
      //Event::create($request-&gt;all());
      //return (gettype($name));
      $data = $request-&gt;all();
      //$newdata =array_keys($data);
      $data= json_decode($data,true);
      $event = New Event;        
      $event-&gt;name = $data['name'];
      $event-&gt;description = $data['description'];
      $event-&gt;start = $data['start'];
      $event-&gt;end = $data['end'];
      $event-&gt;color = $data['color'];
      $event-&gt;save();
  }
  </code></pre>
  
  <p>My jquery</p>
  
  <pre><code>$('#calendar').fullCalendar({
      header: {
          left: 'prev,next today',
          center: 'title',
          right: 'month,agendaWeek,agendaDay'
      },
      events: '/admin/event-list/' + roomId.val(),
      //events: JSON.parse(json_events),
      defaultView: 'agendaWeek',
      editable: true,
      selectable: true,
      timezone: 'local',
      select: function(start, end, jsEvent, view) {
          endtime = end.format('LLLL');
          starttime = start.format('LLLL');
          room_id = roomId.val();
          var mywhen = starttime + ' - ' + endtime;
          startTime.val(start);
          endTime.val(end);
          $('#dayClick #when').text(mywhen);
          $("#dayClick").modal("show");
          $('#submitButton').on('click', function(event){
              console.log("clicked");
              if(createEvent.valid()){
                  // We don't want this to act as a link so cancel the link action
                  if(doSubmit(start, end))
                  {
  
                      $("#dayClick").modal('hide');
                      // remove previous entry
                      $("#createEvent").each(function(){
                          this.reset();
                      });
                      console.log($('#apptStartTime').val());
                      console.log($('#apptEndTime').val());
                      // enter to the calender
                      $("#calendar").fullCalendar('renderEvent',
                          {
                              title: $('#createEvent #event-name').val(),
                              start: new Date($('#apptStartTime').val()),
                              end: new Date($('#apptEndTime').val()),
                          },
                          true);
                      console.log("after renderEvent");
  
                  }
                  else
                  {
                      console.log("failed");
                  };
              }
              event.preventDefault();
          });
  
          //return eventData;
      },
      eventClick: function(event, jsEvent, view) {
          $('#modalTitle').html(event.name);
          $('#modalBody').html(event.description);
          $('#eventUrl').attr({'href':'event/'+event.id,'target':'_self'});
          $('#fullCalModal').modal("show");
      }
  });
  
  function doSubmit(start, end){
      console.log("inside dosubmit");
      eventData.name = eventName.val();
      eventData.description = description.val();
      eventData.capacity = capacity.val();
      eventData.room_id = roomId.val();
      startDate =  moment(start.format("YYYY-MM-DD HH:mm:ss"));
      eventData.start = startDate;
      endDate =  moment(end.format("YYYY-MM-DD HH:mm:ss"));
      eventData.end = endDate;
      eventData.color = color.val();
      console.log("inputdata: " + JSON.stringify(eventData));
      $.ajax({
          type: 'POST',
          url:'/admin/event-ajaxstore',
          //url: '/admin/event-ajaxstore',
          data: JSON.stringify(eventData),
          success: function(response){
              //event.id = response.eventid;
              console.log("returned : " + typeof(response));
              /* $('#calendar').fullCalendar('updateEvent',event); */ 
              /* //json_events = response; */
              /* console.log("data: " + data); */
              return true;
          }
      });
  
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RMM0N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RMM0N.png" alt="enter image description here"></a></p>
  
  <p>When I run this in the contoller;</p>
  
  <pre><code>    $data = $request-&gt;all();
      return (json_decode($data));
  </code></pre>
  
  <p>I get the following error.</p>
  
  <blockquote>
    <p>local.ERROR: ErrorException: json_decode() expects parameter 1 to be
    string, array given in
    /Users/sokada/Code/backpack-aktiv/app/Http/Controllers/Admin/EventController.php:39</p>
  </blockquote>