Skip to content

Commit

Permalink
Merge pull request #15 from FarhanShares/hotfix/migrations
Browse files Browse the repository at this point in the history
Hotfix/migrations
  • Loading branch information
FarhanShares authored Mar 4, 2021
2 parents 110c6f9 + 18b5327 commit 1f38506
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Laravel MediaMan

The most Elegant & Powerful media management package for Laravel!

## Installation

You can install the package via composer:

```bash
composer require farhanshares/laravel-mediaman
```

Once installed, you should publish the provided assets to create the necessary migration and config files.

```bash
php artisan vendor:publish --provider="FarhanShares\MediaMan\MediaManServiceProvider"
```

## Key concepts

There are a few key concepts that should be understood before continuing:

* Media: It can be any type of file. You should specify any file restrictions in your
application's validation logic before you attempt to upload a file.

* MediaUploader: Items are uploaded as its own entity. It does not belong to any other model in the system when it's created, so items can be managed independently (which makes it the perfect engine for a media manager).

* Channel: Media items are bound to "channel". Thus you can easily associate multiple types of media to a model. For example, a model might have an "images" channel and a "documents" channel.

* Collection: A media item can be bundled to any number of "collection".

* Association: Media must be attached to a model for an association to be made.

* Conversion: You can manipulate images using conversions. You can specify conversions to be performed when a media item is associated to a model. For example, you can register a "thumbnail" conversion to run when images are attached to a
model's "gallery" group.

* Conversions are registered globally. This means that they can be reused across your application, i.e a Post and a User can have the same sized thumbnail without having to register the same conversion twice.

### Project is in active development:

Docs will be updated over time, give it a star to support the project.
1 change: 0 additions & 1 deletion config/mediaman.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
'models' => [
'media' => \FarhanShares\MediaMan\Models\Media::class,
'collection' => \FarhanShares\MediaMan\Models\MediaCollection::class,
'mediable' => \FarhanShares\MediaMan\Models\Mediable::class,
],

/*
Expand Down
2 changes: 1 addition & 1 deletion database/migrations/create_mediaman_mediables_table.stub
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CreateMediamanMediablesTable extends Migration

$table->foreign('media_id')
->references('id')
->on(config('mediaman.tables.files'))
->on(config('mediaman.tables.media'))
->onDelete('cascade');
});
}
Expand Down
17 changes: 9 additions & 8 deletions src/MediaManServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ public function register()
*/
public function boot()
{
// the order is important for the migrations to complete
$migrations = [
[
'class_name' => 'CreateMediaManCollectionMediaTable',
'file_name' => 'create_mediaman_collection_media_table'
],
[
'class_name' => 'CreateMediaManCollectionsTable',
'file_name' => 'create_mediaman_collections_table'
Expand All @@ -41,6 +38,10 @@ public function boot()
'class_name' => 'CreateMediaManMediaTable',
'file_name' => 'create_mediaman_media_table'
],
[
'class_name' => 'CreateMediaManCollectionMediaTable',
'file_name' => 'create_mediaman_collection_media_table'
],
[
'class_name' => 'CreateMediamanMediablesTable',
'file_name' => 'create_mediaman_mediables_table'
Expand All @@ -66,20 +67,20 @@ protected function getMigrationFileSource(string $name, string $ext = '.stub')
return __DIR__ . '/../database/migrations/' . $name . $ext;
}

protected function getMigrationFileDestination(string $name, string $ext = '.php')
protected function getMigrationFileDestination(string $name, int $index, string $ext = '.php')
{
return database_path(
'migrations/mediaman/' . date('Y_m_d_His', time()) . $name . $ext
'migrations/' . date('Y_m_d_His', (time() + $index)) . '_' . $name . $ext
);
}

protected function publishMigrations(array $migrations, string $tag = 'migrations')
{
foreach ($migrations as $migration) {
foreach ($migrations as $index => $migration) {
if (!class_exists($migration['class_name'])) {
$this->publishes([
$this->getMigrationFileSource($migration['file_name']) =>
$this->getMigrationFileDestination($migration['file_name'])
$this->getMigrationFileDestination($migration['file_name'], $index)
], $tag);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function up()

$table->foreign('media_id')
->references('id')
->on(config('mediaman.tables.files'))
->on(config('mediaman.tables.media'))
->onDelete('cascade');
});
}
Expand Down

0 comments on commit 1f38506

Please sign in to comment.