I am currently making a POST request to my laravel API using the following code...
fetch('http://laravel.dev/content', {
method: 'POST',
mode:'no-cors',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Access-Control-Allow-Origin':'*'
},
body: JSON.stringify({
})
})
.then((response) => {
console.log(response);
});
The route looks as follows...
Route::post('/content', array('middleware' => 'cors', 'uses' => 'Test@save'));
Although I have configured cors mode, I am actually using no-cors.
My controller Test@save looks like...
class Test extends Controller
{
public function save()
{
echo "here";
}
}
I am trying to send the string here back to the fetch request. But in my fetch request, when I do console.log(response), I get the following response...
Response {type: "opaque", url: "", status: 0, ok: false, statusText: "" ...}
Is there any way to send a custom response using my Laravel route? If so, how do I do so?