Skip to content
An example project to display how the spatie mediaLibrary could handle a polymorphic many to many db
PHP HTML Vue
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
.idea
app
bootstrap
config
database
public
resources
routes
storage
tests
.editorconfig
.env.example
.gitattributes
.gitignore
.styleci.yml
LICENSE
artisan
composer.json
composer.lock
package.json
phpunit.xml
readme.md
server.php
webpack.mix.js
yarn.lock

readme.md

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

You can’t perform that action at this time.