Last active
October 7, 2015 21:47
-
-
Save raank/0d6d99515dc8da779227 to your computer and use it in GitHub Desktop.
Testes com AngularJS + Laravel 5.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- DASHBOARD view of controller DashboardController --> | |
<form ng-submit="testEntry()"> | |
<input type="text" name="data.nome"> | |
<button type="submit">Enviar</button> | |
</form> | |
{{ result }} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TokenMismatchException in VerifyCsrfToken.php line 53 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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