Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Modules/Media/Models/Media.php

Open in GitHub
class Media extends Model
{
//
public function imageable()
{
return $this->morphTo();
}
}

Modules/Media/Database/Migrations/2022_04_28_092229_create_media_table.php

Open in GitHub
class 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 GitHub
class Category extends Model
{
//
public function images(): \Illuminate\Database\Eloquent\Relations\MorphMany
{
return $this->morphMany(Media::class, 'mediaable');
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.