Laravel MorphTo() inducing infinite load time and white screen

49 Views Asked by At

I have a CalendarEvent Model which has a morphTo (polymorphic) relationship to multiple models, one being StaffRoster.

When the relation is called, laravel seems to 'hang' with the webpage taking forever to load, and if it does load, a blank, white page is served.

the code is as follows:

Migrations:

Schema::create('calendar_event', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->morphs("model");
            $table->text("google_calendar_id");
            $table->date("event_date");
            $table->timestamps();
        });
Schema::create('staff_roster', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger("users_id");
            $table->date("date");
            $table->time("start_time");
            $table->time("end_time");
            $table->timestamps();
        });

Models:

class StaffRoster extends Model
{
    protected $table = "staff_roster";
    protected $guarded = [];
    protected $with = [
        "calendar_event"
    ];

    public function calendar_event(){
        return $this->morphOne("App\CalendarEvent", "model");
    }
}

class CalendarEvent extends Model
{
    protected $table = "calendar_event";

    protected $with = [
      "model",
    ];

    protected $fillable = [
        "model_type",
        "model_id",
        "event_date",
        "google_calendar_id",
    ];

    public function model(){
        return $this->morphTo();
    }
}

the glue:

dd(CalendarEvent::find(1)); // Hangs 

Any help with this would be greatly appreciated!

0

There are 0 best solutions below