Skip to content

An example project to display how the spatie mediaLibrary could handle a polymorphic many to many db

License

Notifications You must be signed in to change notification settings

Mikaleb/PolyMany-MediaLibrary

 
 

Repository files navigation

header

Welcome to PolyMany MediaLibrary 👋

forthebadge

GitHub issues GitHub license GitHub language count Laravel 5.8 GitHub forks

Based on an empty Laravel 5.8, this repository shows how the Spatie Media Library could handle a polymorphic many to many DB.

Install

git clone
composer install
npm install
php artisan key:generate

Getting Started

Follow the install instructions to init Laravel, copy the .env.example file to a .env file and set your database information to get started. Then generate the data to it via

php artisan migrate --seed

How it works

Database

A Mediable table is added to have a many-to-many polymorphic relationship possible to any model that has a media :

Schema::create('mediables', function (Blueprint $table) {

$table->integer("media_id");

$table->integer("mediable_id");

$table->string("mediable_type");

$table->string("tag");

$table->integer("order");

$table->timestamps();

});

Trait

To add the possibility for the models to have this polymorphic link, we create a trait :

<?php

namespace App\Traits;

trait HasMediaTuto

{

/**

* @return mixed

*/

public function medias()

{

return $this->morphToMany(\App\Media::class, 'mediable');

}

}

And in any model plus your user model : use HasMediaTuto

Author

👤 Epistol

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator

About

An example project to display how the spatie mediaLibrary could handle a polymorphic many to many db

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 81.6%
  • Blade 17.3%
  • Other 1.1%