spatie / laravel-activitylog

Log activity inside your Laravel app
https://docs.spatie.be/laravel-activitylog
MIT License
5.3k stars 712 forks source link

Unable To Query Morph To Relationships + Nested Eager Loading Morph To Relationships #1198

Closed folio3-hasan closed 11 months ago

folio3-hasan commented 1 year ago
`public function getActivityLogs(Request $request)
    {
        $perPage = (intval($request->per_page) > 0) ? intval($request->per_page) : 15;
        $activityLogs = ActivityLog::query();
        if (!isAdmin() && auth()->check()) {
            $activityLogs = $activityLogs->causedBy(auth()->user());
        }
        $activityLogs = $activityLogs->with(['causer', 'subject' => function (MorphTo $morphTo) {
            $morphTo->morphWith([
                Application::class => ['school', 'user'],
                UserMeta::class => ['user'],
                SchoolSurvey::class => ['user'],
            ]);
        }]);
        $activityLogs = $activityLogs->whereHasMorph('subject', [Application::class, UserMeta::class, SchoolSurvey::class],
            function (Builder $query) {
                return $query->where('user_id', 92);
            });
        if (!empty($request->log_name)) {
            $activityLogs = $activityLogs->inLog([$request->log_name]);
        }
        return $activityLogs->latest()->paginate($perPage);
    }`

Here above is the code I have written; the function unable to fetch nested eager loading morph to relationships, also unable to query morph to relationships.

spatie-bot commented 11 months ago

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

shabyis commented 4 days ago

There is no solution provided for this bug, anyone?