为什么我的Laravel变形贴图返回为空

为什么我的Laravel变形贴图返回为空,laravel,Laravel,我有一张这样的桌子: Schema::create('comments', function (Blueprint $table) { $table->increments('id'); $table->integer('user_id'); $table->integer('comment_id'); $table->string('comment_type'); $table-&g

我有一张这样的桌子:

    Schema::create('comments', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id');
        $table->integer('comment_id');
        $table->string('comment_type');
        $table->text('comment');
        $table->timestamps();
    });
其填充方式如下:

INSERT INTO `job`.`comments` (`id`, `user_id`, `comment_id`, `comment_type`, `comment`, `created_at`, `updated_at`) VALUES ('1', '1', '8', 'courses', 'Hello', NULL, NULL);
我有一个这样的课程模式:

<?php

namespace App\Modules\Courses\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
use Laravelista\Comments\Comments\Traits\Comments;

class Courses extends Model
{
    use Comments;

    protected $table = 'courses';

    public function comments()
    {
        return $this->morphMany('App\Modules\Comments\Models\Comments', 'comment');
    }

我做错了什么,我该如何解决

编辑:我也尝试过将其放在我的应用程序服务提供商中的建议,但也没有成功:


尝试在服务提供商中注册Relation::morphMap()

AppServiceProvider

use Illuminate\Database\Eloquent\Relations\Relation;
...
public function boot()
{
    Relation::morphMap([
         'courses' => 'App\Modules\Courses\Models\Courses',
    ]);
}

@randomman尝试以下关系::morphMap(['courses'=>courses::class,]);可悲的是,仍然是same@randommman重新启动artisan tinker并尝试:App\Modules\Courses\Models\Courses::find(8)->coments()->get()->toArray();你说得对@Leo_Kelmendi,Tinker必须重新启动才能使更改生效。编辑,nvm已修复。谢谢:)
INSERT INTO `job`.`comments` (`id`, `user_id`, `comment_id`, `comment_type`, `comment`, `created_at`, `updated_at`) VALUES ('1', '1', '8', 'App\\Modules\\Courses\\Models\\Courses', 'Hello', NULL, NULL);
use Illuminate\Database\Eloquent\Relations\Relation;
...
public function boot()
{
    Relation::morphMap([
         'courses' => 'App\Modules\Courses\Models\Courses',
    ]);
}