-
Modules/Media/Models/Media.php
Open in GitHubclass Media extends Model { // public function imageable() { return $this->morphTo(); } }
-
Modules/Media/Database/Migrations/2022_04_28_092229_create_media_table.php
Open in GitHubclass CreateMediaTable extends Migration { public function up() { Schema::create('media', function (Blueprint $table) { $table->id(); $table->json('files'); $table->string('name', 255); $table->enum('type', ['image', 'video', 'audio', 'zip', 'doc']); $table->boolean('isPrivate'); $table->foreignId('user_id')->constrained()->onDelete('cascade'); $table->morphs('mediaable'); $table->timestamps(); }); } /// }
-
Modules/Category/Models/Category.php
Open in GitHubclass Category extends Model { // public function images(): \Illuminate\Database\Eloquent\Relations\MorphMany { return $this->morphMany(Media::class, 'mediaable'); } // }