0

I have installed laravel homestead, and it works properly I am able communicate with the backend and get a respons using the API. Now I also installed angularjs it seems to work also, but what is not working is to POST or GET to the laravel API from the Angular app as frontend. I am getting the following errors in firefox inspector Network:

405 Method Not Allowed
request headers 
Host: demo.app:8000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:37.0) Gecko/20100101 Firefox/37.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Origin: http://frontend.app:8000
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

Response Header
Cache-Control: no-cache
Connection: keep-alive
Content-Type: text/html; charset=UTF-8
Date: Fri, 01 May 2015 02:28:25 GMT
Server: nginx/1.6.2
Set-Cookie: laravel_session=
Transfer-Encoding: chunked

and in the console log:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://demo.app:8000/myUrl This can be fixed by moving the resource to the same domain or enabling CORS.

I am not really sure why they are not communicating I followed all the instructions properly plus they are working fine independently (Laravel API, and Angularjs for frontend). Any thoughts and help will be appreciated

user1518071
  • 49
  • 2
  • 8

1 Answers1

2

you need to add / replace these lines in your /app/filters.php

App::before(function ($request) {
    header("Access-Control-Allow-Origin: *");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
});
DevManny
  • 1,326
  • 1
  • 9
  • 10
  • DevManny, it's a big project with a lot of files already; I just changed the environment recently, moving it to a different network that when the problem is happening but when I am on the old network everything works fine. I don't know if you are asking for me to post the whole projects here or just the relevant codes. But anyways I included few codes I feel relevant asa an answer: – user1518071 May 04 '15 at 03:20
  • I haven't seen filters.php files in laravel 5.6 – Ketav Mar 19 '18 at 13:03