1
My minimum is the following, I am developing an API for a bakery, where it may be on the same server or different server, I am using the framework laravel
in the version 5.2.*
. In order to facilitate the work I made some controllers only on painel administrativo
for example products. In my controllers I check if a json request is coming. This way I know if it’s a request or if it’s a view I should return, I programmed it this way:
public function index(){
$produtos = Produto::all();
if(Request::wantsJson()){
return $produtos;
}else{
return view('Produto.listProduto', compact('produtos'));
}
}
That being said and done all process and the same being tested, I’m trying to consume this data from another website, which in case would be the main site. My idea is to list all products and return them to a JSON.
In html I use JQUERY to make this request this way:
$.getJSON('http://localhost:8000/produtos', function(data) {
console.log(data);
});
On my route in the painel administrativo
I programmed it this way:
Route::singularResourceParameters();
Route::resource('produtos', 'ProdutoController');
With everything going wrong on console
of my browser
, use the google chrome
but tested on others and gave the same kind of problem.
The exit was
Blocked cross-origin request: Same Origin Policy (Same Origin Policy) prevents reading the remote resource at http://localhost:8000/products. (Reason: CORS header 'Access-Control-Allow-Origin' is not present).
What can I do wrong ?
how would I do this ;
– Renan Rodrigues
I made an issue.
– novic
Could not open input file: Composer.phar dropped this error in the log
– Renan Rodrigues
I gave Poser require and it worked
– Renan Rodrigues
I made a brief summary and sequence of commands @Renanrodrigues !
– novic
Only does the . phar change because here in mine it didn’t work this way, the other one went straight
– Renan Rodrigues
What is your system?
– novic
my system is windows 10
– Renan Rodrigues
should work but, all right!
– novic
actually is the name of the document, is Composer.json no Composer.phar
– Renan Rodrigues
kkkkkkkkkkkkkkkk I imagine it was something wrong right there! because I use it because I use windows 10, but without problems install that step by step it will release for you! have settings I’ll put in answer!
– novic