Laravel version: 5.6
PHP version: 7.1
I finished my project and tested it locally. But when I uploaded it on a shared hosting site, I get two errors (I'm not sure if they're two separate errors):
DELETE http://SomeAddress/patients/440627036 403 (Forbidden)
Failed to load http://SomeAddress/patients/440627036: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://SomeAddress' is therefore not allowed access. The response had HTTP status code 403.
It was CORS issue which I think I fixed. I was getting CORS error for only PUT and DELETE (I don't know why POST and GET were working!). I added the required headers and this error went away.These are the headers I added:
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS')
->header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With')
->header('Access-Control-Allow-Credentials', 'true')
->header('Access-Control-Max-Age', '10000');
But now I get another error (again only happens for PUT and DELETE) - (Is it related to Laravel or my shared hosting site or my backend code?):
Forbidden
You don't have permission to access /patients/440627035 on this server.
Has my CORS issue been solved completely? How can I fix these errors?
Frontend (I use AngularJS $resource to send my HTTP requests):
this.patientRes = function () {
return $resource(baseURL + 'patients/:id', {id: "@id"}, {
get: {
method: 'GET',
isArray: true,
headers: {'Content-Type': 'application/json'}
},
update: {
method: 'PUT',
headers: {'Content-Type': 'application/json'}
},
delete: {
method: 'DELETE',
headers: {'Content-Type': 'application/json'}
}
})
};
Update:
My file structure was like this:
public_html/public/ and my files were here
I change it to:
public_html/ and my files are now here