Rückkehr habe ich eine Tabelle wie folgt:Warum ist mein Laravel Morphmap leer
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();
});
, die wie so bevölkert ist:
INSERT INTO `job`.`comments` (`id`, `user_id`, `comment_id`, `comment_type`, `comment`, `created_at`, `updated_at`) VALUES ('1', '1', '8', 'courses', 'Hello', NULL, NULL);
ich ein Kursmodell wie so haben:
<?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');
}
, die mein Kommentarmodell mit meiner Morph-Karte verwandelt:
<?php
namespace App\Modules\Comments\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
Relation::morphMap([
'courses' => App\Modules\Courses\Models\Courses,
]);
class Comments extends Model
{
public function commentable()
{
return $this->morphTo();
}
}
Wenn ich meine Karte in meiner Reihe und Verwendung Kursen an der Art Referenz gibt es leer, wie Sie von Tinker sehen:
Aber wenn ich den vollständigen Namensraum im comment_type in der Datenbank funktioniert es:
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);
Was mache ich falsch, und wie kann ich dieses Problem beheben?
edit: Ich habe auch versucht, die Vorschläge von zu ihm in meinen App Service-Provider platzieren, aber das weder funktioniert nicht:
haben versucht, das auch und immer noch die gleichen http://i.imgur.com/z929bBe.png –
@randommman versuchen, diese Beziehung :: morphMap ([ 'Kurse' => Kurse :: Klasse, ]) ; –
Leider immer noch das gleiche –