G
G
GaserV2015-12-31 14:59:57
Angular
GaserV, 2015-12-31 14:59:57

Why is Laravel not outputting data from post?

Why is Laravel not outputting data from post? When I just return $formData it outputs like: {{"title":"you","text":"you"}: ""} But when I try to output something like $formData['title'] then he writes, they say:
ErrorException in UserController.php line 13:
Undefined index: title

<?php namespace App\Http\Controllers;

use Illuminate\Http\Response;
use App\Http\Controllers\Controller;
use Request;

class UserController extends Controller 
{
  public function index() {

    $formData = Request::all();

    return $formData;

  }
}

?>

$scope.sendform = function(e) {
  		e.preventDefault();
  		$scope.formData = {};
  		
  		var title = this.title;
  		var text  = this.text;

  		var req = {
     method: 'POST',
     url: '/send',
     headers: {'Content-Type': 'application/x-www-form-urlencoded'},
     data: { title: title, text: text }
    }

    $http(req).then(function(){
      alert("success!")
    }, function(){
      alert("error!")
    });

  	}

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
Nicholas, 2015-12-31
@healqq

headers: {'Content-Type': 'application/x-www-form-urlencoded'},
     data: { title: title, text: text }

This code will not send you requests to application/x-www-form-urlencoded . By default, Angular sends all requests to application/json . To get around this, you need to define the transformRequest function, which will make a urlencoded string from your data.
To do this, you can use the jQuery.param() function, for example .
PS I recommend enabling the ability to process application/json as body on the backend, much less hassle.
For your case it will look like this:
function transformRequest(data) {
  return $.param(data);
}
var req = {
  method: 'POST',
  url: '/send',
  data: {title: this.title, text: this.text},
  transformRequest: transformRequest,
  headers: {'Content-Type': 'application/x-www-form-urlencoded'},
}

Y
Yuri Udovichenko, 2014-06-10
@mihael90

Firstly, I can advise the online broadcast service - www.ustream.tv in addition to the one above.
Secondly, if you have thoughts about making money on online broadcasting, you should look at creating your own broadcasting mechanism, it's not that difficult. I wrote a note not so long ago about the choice between free services and my own solutions, perhaps this will give food for thought.

A
Alexander Taratin, 2014-06-10
@Taraflex

www.smotri.com/info/?page=broadcast

V
Vladimir Sokolov, 2016-08-31
@tort2

Here are instructions for setting up Wirecast software, OpenBroadcaster and a number of other programs to work with the Facecast service .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question