For context, I do have 2 Laravel projects on my local unit. 1 for the app and 1 for internal API. The app will send API request to the internal API. I expected for the Laravel homestead to work smoothly but I encountered a problem wherein I keep on getting null response from internal API.
I tried to add exception to VerifyCsrfToken class as commented here.
I also tried to clear cache by running
php artisan optimize:clear
and vagrant provision
vagrant reload --provision
The goal is for the app to have a successful response from internal API. Please help me, I am stuck.
On my internal API project (email-sender-api - routes/api.php).
Route::get('/tasks', function () {
return 'test';
});
On my app project (email-sender-app - routes/web.php).
Route::get('/test', function () {
$url = 'https://email-sender-api.local.com/api/tasks';
// Initialize cURL session
$curl = curl_init();
// Set cURL options
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
// Execute the GET request
$response = curl_exec($curl);
// Check for errors
if ($response === false) {
$error = curl_error($curl);
echo "Error: " . $error;
} else {
// Process the response
$data = json_decode($response, true);
// Assuming the response is in JSON format, you can decode it into an associative array
// Close the cURL session
curl_close($curl);
// Display the response
dd('response', $data);
}
});
My setup
- /etc/hosts (C drive)
192.168.56.56 email-sender-api.local.com
192.168.56.56 email-sender-app.local.com
- Homestead.yaml
---
ip: "192.168.56.56"
memory: 2048
cpus: 2
provider: virtualbox
authorize: C:/Users/mena/.ssh/id_rsa.pub
keys:
- C:/Users/mena/.ssh/id_rsa
folders:
- map: D:/mena/email-sender/email-sender-app
to: /home/vagrant/code/email-sender/email-sender-app
- map: D:/mena/email-sender/email-sender-api
to: /home/vagrant/code/email-sender/email-sender-api
sites:
- map: email-sender-app.local.com
to: /home/vagrant/code/email-sender/email-sender-app/public
php: "8.1"
type: "apache"
- map: email-sender-api.local.com
to: /home/vagrant/code/email-sender/email-sender-api/public
php: "8.1"
type: "apache"
databases:
- homestead
- task
features:
- mysql: true
- mariadb: false
- postgresql: false
- ohmyzsh: false
- webdriver: false
services:
- enabled:
- "mysql"
- "redis-server"
# - disabled:
# - "postgresql@11-main"
#ports:
# - send: 33060 # MySQL/MariaDB
# to: 3306
# - send: 4040
# to: 4040
# - send: 54320 # PostgreSQL
# to: 5432
# - send: 8025 # Mailhog
# to: 8025
# - send: 9600
# to: 9600
# - send: 27017
# to: 27017