I have been doing research and nothing I have found has made any sense to me. I am totally new to laravel and I am wanting to use it as a backend to my AngularJS. I have good experience with angular so here is my controller function making the http call:
var jsonData = {
text: "test"
};
$http.post("http://127.0.0.1:8000/submit", {
data: jsonData
}).then(function(response) {
console.log("SUCCESS");
})
And then here is my route in file api.php:
Route::post('/submit', function(Request $request) {
$data = $request->input('data');
return $data;
});
So then I run php artisan serve and the console says Laravel development server started: <http://127.0.0.1:8000>. I try to reach the server via angular and nothing happens. I was wondering if someone can help me figure out what I am doing wrong? How can I post my data from angular to laravel and then send it back to my angular?
http://127.0.0.1:8000in my browser and the Laravel template shows up. It is running just via my terminal. I get no response. In the console of my angular site:[Error] Origin null is not allowed by Access-Control-Allow-Origin. [Error] Failed to load resource: Origin null is not allowed by Access-Control-Allow-Origin. [Error] XMLHttpRequest cannot load http://127.0.0.1:8000/submit due to access control checks.So I installed:composer require barryvdh/laravel-corsstill no success/publicdirectory of your laravel installation, and you can access it ashttp://127.0.0.1:8000/angularjs-filename.html. I'm currently running angularjs within laravel, you just need to have the file structures correct.php artisan routeon the command line to make sure that the two match.