0

我有一个 CalendarEvent 模型,它与多个模型具有 morphTo(多态)关系,其中一个是 StaffRoster。

当调用关系时,laravel 似乎“挂起”了网页,需要永远加载,如果确实加载,则会提供一个空白的白色页面。

代码如下:

迁移:

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();
        });

楷模:

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();
    }
}

胶水:

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

对此的任何帮助将不胜感激!

4

0 回答 0