Skip to content

Commit

Permalink
Added combinable types to media types
Browse files Browse the repository at this point in the history
  • Loading branch information
marioSantos97 committed Oct 27, 2022
1 parent 700efa4 commit 6de1ad6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/app/Http/Controllers/Admin/MediaTypeCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ protected function setupListOperation()
'label' => 'Allowed Extensions',
]);

// CRUD::addColumn([
// 'type' => 'relationship',
// 'name' => 'mediaVersions',
// 'label' => 'Media Versions',
// ]);
CRUD::addColumn([
'type' => 'relationship',
'name' => 'combinableTypes',
'label' => 'Combinable Media Types',
]);
}

protected function setupCreateOperation()
Expand All @@ -74,6 +74,12 @@ protected function setupCreateOperation()
'inline_create' => ['entity' => 'media-version'],
]);

CRUD::addField([
'type' => 'relationship',
'name' => 'combinableTypes',
'label' => 'Combinable Media Types',
]);

CRUD::addField([
'type' => 'select2_from_array',
'name' => 'extensions',
Expand Down
5 changes: 5 additions & 0 deletions src/app/Models/MediaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ public function mediaVersions()
{
return $this->belongsToMany(MediaVersion::class, 'media_type_has_versions', 'media_type_id', 'media_version_id');
}

public function combinableTypes()
{
return $this->belongsToMany(MediaType::class, 'media_types_has_combinations', 'media_type_id', 'combinated_media_type_id');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMediaCombinations extends Migration
class AddMediaCombinations extends Migration
{
public function up()
{
Schema::create('media_types_has_combinations', function (Blueprint $table) {
$table->foreignId('media_type_id')->constrained('media_types');
$table->foreignId('combinated_media_type_id')->constrained('media_types');
});

Schema::create('media_has_combinations', function (Blueprint $table) {
$table->foreignId('media_id')->constrained('medias');
$table->foreignId('combinated_media_id')->constrained('medias');
Expand Down

0 comments on commit 6de1ad6

Please sign in to comment.