I have two laravel project with virtual host name 1) my.dev.com and 2) your.dev.com
I have create api for set cookie for cross domain and api is located at your.dev.com
Route::middleware('cors')->get('/hello', function () {
$cookie = Cookie::make('custom_cookie', 'hello_world', 10, "/", '.dev.com');
return response()->json('Hello worlds')->withCookie($cookie);
});
I make api call from my.dev.com
and code is like this
<html>
<head>
<title>CORS</title>
</head>
<body>
<button type="button">Call API</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("body").on("click","button",function () {
$.get("http://my.dev.com/api/hello",function(data){
alert(data);
});
})
});
</script>
</body>
When I click Call API button from my.dev.com
I get response Hello worlds
but Cookie is not set your.dev.com
Even Cookie not set any .dev.com
virtual host
I want to set Cookie at your.dev.com
from my.dev.com
with help of Ajax and code already posted here.
Your help would be appreciated.