How this page was checked: The PHP was not executed - there is no PHP runtime on the build machine. The request it builds (same URL, headers and JSON body) was sent with curl to the in-memory API; the chart values, the whole_sign 400 and the string-number 400 are from those runs.
The controller
Config is the same as the quickstart: services.astronode.key and services.astronode.base_url, read from .env in config/services.php.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Illuminate\Validation\Rule;
class NatalChartController extends Controller
{
public function __invoke(Request $request)
{
$v = $request->validate([
'date' => ['required', 'date_format:Y-m-d'],
'time' => ['required', 'regex:/^\d{2}:\d{2}(:\d{2})?$/'],
'tz_offset_minutes' => ['required', 'integer', 'between:-840,840'],
'lat' => ['required', 'numeric', 'between:-90,90'],
'lng' => ['required', 'numeric', 'between:-180,180'],
'house_system' => ['nullable', Rule::in(['placidus', 'koch', 'equal', 'whole-sign', 'porphyry'])],
]);
// Form posts arrive as strings; the API wants JSON numbers.
$body = [
'date' => $v['date'],
'time' => $v['time'],
'tz_offset_minutes' => (int) $v['tz_offset_minutes'],
'lat' => (float) $v['lat'],
'lng' => (float) $v['lng'],
'house_system' => $v['house_system'] ?? 'placidus',
];
$chart = Cache::rememberForever('natal:' . hash('sha256', json_encode($body)), function () use ($body) {
return Http::withToken(config('services.astronode.key'))
->baseUrl(config('services.astronode.base_url'))
->acceptJson()
->timeout(15)
->retry(2, 300, fn ($e) => $e instanceof ConnectionException)
->post('/v1/western/natal/chart', $body)
->throw()
->json('data');
});
return view('charts.natal', ['chart' => $chart]);
}
}- The
timerule mirrors the API's own pattern, so an HTML<input type="time">value without seconds (17:25) is accepted on both sides. retry(...)only retries connection failures. A400will fail identically on every attempt, and retrying a429after 300 ms just spends the next slot; readRetry-Afterinstead.rememberForevernever caches a failure -throw()raises before the closure returns.
Rendering it in Blade
resources/views/charts/natal.blade.php:
<h2>Ascendant {{ $chart['ascendant']['sign'] }} {{ number_format($chart['ascendant']['degree'], 2) }}°</h2>
<p>Midheaven {{ $chart['midheaven']['sign'] }} {{ number_format($chart['midheaven']['degree'], 2) }}°</p>
<table>
@foreach ($chart['planets'] as $p)
<tr>
<th>{{ $p['planet'] }}@if ($p['retrograde']) (R)@endif</th>
<td>{{ $p['sign'] }} {{ number_format($p['degree_in_sign'], 2) }}°</td>
<td>House {{ $p['house'] }}</td>
</tr>
@endforeach
</table>For the sample birth with house_system: "whole-sign" the response had ascendant Libra 13.24°, midheaven Cancer 12.88°, and the Sun at Taurus 4.16° in house 8. With the default Placidus houses the same Sun sits in house 7 - the planet does not move, the house boundaries do (house systems). The response also carries houses (cusps) and the outer planets, which a wheel drawing needs.
The mistakes that bite first
- Passing validated form input straight through.
$request->validate()checks thatlatis numeric but returns it as the string the form sent.Http::postthen encodes"lat": "19.076", and the API answers400 VALIDATION_ERROR- "Invalid input: expected number, received string". Cast, as the controller does. - `whole_sign` vs `whole-sign`. Vedic responses report their house system as
"whole_sign"inmeta; the Western endpoints'house_systeminput takes"whole-sign". Sending the underscore form returned a400listing the five accepted values - validate against that list withRule::in, as above. - `env()` outside config files. After
php artisan config:cache,env('ASTRONODE_API_KEY')returnsnullat runtime and every call is a401. Read the key throughconfig(...)only.
Questions
- Which AstroNode endpoints does the Laravel / PHP example call?
- 2 endpoints: Western Natal Chart (
POST /v1/western/natal/chart); Western Natal Planets (POST /v1/western/natal/planets). - Was the Laravel / PHP code on this page actually run?
- The PHP was not executed - there is no PHP runtime on the build machine. The request it builds (same URL, headers and JSON body) was sent with curl to the in-memory API; the chart values, the
whole_sign400 and the string-number 400 are from those runs.