Skip to content

Instantly share code, notes, and snippets.

@raank
Last active October 7, 2015 21:47
Show Gist options
  • Save raank/0d6d99515dc8da779227 to your computer and use it in GitHub Desktop.
Save raank/0d6d99515dc8da779227 to your computer and use it in GitHub Desktop.
Testes com AngularJS + Laravel 5.1
<!-- DASHBOARD view of controller DashboardController -->
<form ng-submit="testEntry()">
<input type="text" name="data.nome">
<button type="submit">Enviar</button>
</form>
{{ result }}
app.controller('DashboardController', ['$rootScope', '$scope', '$routeParams', '$route', '$http', DashboardController]);
function DashboardController( $rootScope, $scope, $routeParams, $route, $http )
{
$scope.testEntry = function() {
$http({
method: "POST",
url: 'http://api.cms.local/teste',
data: {
name: $scope.data
},
})
.success(function(data, status, headers, config)
{
$scope.result = status + ' - ' + data;
})
.error(function(data, status, headers, config)
{
$scope.result = 'error:' + data + ' - ' + status;
});
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class Post extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$input = Input::json();
$input_array = (array)$input;
$rules = array(
'name' => 'required'
);
$val = Validator::make($input_array, $rules);
if(! $val->fails() ) {
$data = array('msg' => 'all good', 'name' => $input_array);
} else {
$data = array('msg' => $val->errors->all());
}
return Response::json($data);
}
}
TokenMismatchException in VerifyCsrfToken.php line 53
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('welcome');
});
// Controller for tests
Route::post('teste', 'Post@index');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment