Skip to content
This repository has been archived by the owner on Nov 16, 2021. It is now read-only.

Commit

Permalink
Use morph mapping for attachables
Browse files Browse the repository at this point in the history
  • Loading branch information
wimski committed May 5, 2021
1 parent 3e349b9 commit 50ca640
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Handlers/DeleteAttachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct($field)
*/
public function __invoke(Request $request, $model)
{
Attachment::where('attachable_type', get_class($model))
Attachment::where('attachable_type', $model->getMorphClass())
->where('attachable_id', $model->getKey())
->get()
->each
Expand Down
2 changes: 1 addition & 1 deletion src/Models/PendingAttachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function persistDraft($draftId, Froala $field, $model)
public function persist(Froala $field, $model)
{
Attachment::create([
'attachable_type' => get_class($model),
'attachable_type' => $model->getMorphClass(),
'attachable_id' => $model->getKey(),
'attachment' => $this->attachment,
'disk' => $field->disk,
Expand Down
9 changes: 4 additions & 5 deletions tests/Fixtures/TestServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

namespace Froala\NovaFroalaField\Tests\Fixtures;

use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\ServiceProvider;

class TestServiceProvider extends ServiceProvider
{
public function boot()
{
}

public function register()
{
$this->app['config']->set('nova.froala-field.attachments_driver', 'trix');
Relation::morphMap([
'article' => Article::class,
]);
}
}
3 changes: 1 addition & 2 deletions tests/FroalaUploadControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Froala\NovaFroalaField\Models\Attachment;
use Froala\NovaFroalaField\Models\PendingAttachment;
use function Froala\NovaFroalaField\nova_version_at_least;
use Froala\NovaFroalaField\Tests\Fixtures\Article;
use Illuminate\Support\Facades\Storage;

class FroalaUploadControllerTest extends TestCase
Expand Down Expand Up @@ -58,7 +57,7 @@ public function store_attachment()
'attachment' => $this->getAttachmentLocation(),
'url' => Storage::disk(static::DISK)->url($this->getAttachmentLocation()),
'attachable_id' => $response->json('id'),
'attachable_type' => Article::class,
'attachable_type' => 'article',
]);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Froala\NovaFroalaField\FroalaFieldServiceProvider;
use Froala\NovaFroalaField\Tests\Fixtures\TestResource;
use Froala\NovaFroalaField\Tests\Fixtures\TestServiceProvider;
use Froala\NovaFroalaField\Tests\Fixtures\User;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Route;
Expand Down Expand Up @@ -49,6 +50,7 @@ protected function getPackageProviders($app)
NovaServiceProvider::class,
NovaApplicationServiceProvider::class,
FroalaFieldServiceProvider::class,
TestServiceProvider::class,
];
}

Expand Down

0 comments on commit 50ca640

Please sign in to comment.