You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then when Morph query builder load media, comments query will like this one:
selectcount(*) as aggregate from`comments`where`comments`.`content_type`='App\\Models\\Post'and`comments`.`content_id`=10and`comments`.`content_id`is not null
But actual value in DB is 'TomatoPHP\\FilamentCms\\Models\\Post' .
Currently. I must used workaround hack: reupdate value when post created and update. But when comment added. Post is remain unchanged
namespaceApp\Listeners;
useTomatoPHP\FilamentCms\Events\PostCreated;
useTomatoPHP\FilamentCms\Events\PostUpdated;
useIlluminate\Support\Facades\DB;
class UpdatePostMediaModelType
{
/** * Handle the event. */publicfunctionhandle(PostCreated|PostUpdated$event): void
{
// Update media model_type for the specific postDB::table('media')
->where('model_type', 'TomatoPHP\FilamentCms\Models\Post')
// ->where('model_id', $event->post->id)
->update(['model_type' => 'App\Models\Post']);
DB::table('comments')
->where('model_type', 'TomatoPHP\FilamentCms\Models\Post')
// ->where('model_id', $event->post->id)
->update(['model_type' => 'App\Models\Post']);
}
}
The text was updated successfully, but these errors were encountered:
Some times, Developers used this package need to override default model or extend it.
So used hardcoded model name in
Morph
relations will break.Here is example in my case:
File :
app/Models/Post.php
Then when
Morph
query builder load media, comments query will like this one:But actual value in DB is
'TomatoPHP\\FilamentCms\\Models\\Post'
.Currently. I must used workaround hack: reupdate value when post created and update. But when comment added. Post is remain unchanged
The text was updated successfully, but these errors were encountered: