area17 / twill

Twill is an open source CMS toolkit for Laravel that helps developers rapidly create a custom admin console that is intuitive, powerful and flexible. Chat with us on Discord at https://discord.gg/cnWk7EFv8R.
https://twillcms.com
Apache License 2.0
3.78k stars 574 forks source link

502 Bad Gateway when calling getRelated in frontend #2181

Closed aljazromih closed 8 months ago

aljazromih commented 1 year ago

Description

I get 502 Bad Gateway when calling getRelated() in a controller or blade on frontend. If I call it in a repeater blade (for dynamic select options) it works with no errors.

Controller, blade view (502 Bad Gateway)

$this->service = Service::forSlug($service)->published()->firstOrFail();
$this->doctors = $this->service->getRelated('doctors');
// dd($this->doctors);
// foreach ($this->service->getRelated('doctors') as $doctor) {
//     dd($doctor);
// }
{{-- @dd($service->getRelated('doctors')) --}}
@foreach ($service->getRelated('doctors') as $doctor)
  {{-- @dd($doctor) --}}
  <div>
    ...
  <div>
@endforeach

If I uncomment the dd(), @dd() (also in the foreach loop) above it works & returns a collection of the related models or single model within the foreach: This is an image

Sample in repeater blade view (works)

foreach (\App\Models\Service::find($service)->getRelated('doctors') as $doctor) {
  $doctorOptions[] = [
    'value' => $doctor->id,
    'label' => $doctor->title
  ];
}

Versions

Twill version: 2.12.4 Laravel version: 9.48.0 PHP version: 8.0

ifox commented 1 year ago

The 502 error is coming from your web server, but there must be an underlying error in your Laravel application for it to happen. Check your Laravel logs.

aljazromih commented 1 year ago

No error in log

The 502 error is coming from your web server, but there must be an underlying error in your Laravel application for it to happen. Check your Laravel logs.

ifox commented 1 year ago

What about your web server/php-fpm logs?

aljazromih commented 1 year ago

What about your web server/php-fpm logs?

Couldn't find any error.

ifox commented 1 year ago

Are you still reproducing this issue?