Retrieve Activity Logs on a Model with LogActivity Trait #750
-
Hi, been trying to find in your docs on how do I retrieve the logs on a Specific Model? (it's always "get last activity" on examples but I'm looking for enumerating logs that have been performed on that specific model) I'm not getting results from return $model->activity; Do I need to define the relationship of the Model with the Activity Model? My aim is to get logs of the model and show the causer and changes made by the causer. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hi, you can do: Hope that helps. |
Beta Was this translation helpful? Give feedback.
-
At first, I wonder how you've created this as an issue? The only way I've found would be that you've used the "Bug" template and removed the label? Or have you accessed https://github.com/spatie/laravel-activitylog/issues/new directly? Or is there another way GitHub does not cover with the current settings? From the subject model perspective you can use the laravel-activitylog/src/Traits/LogsActivity.php Lines 80 to 83 in b07e562 If you want to show all activities done by an user you can use the laravel-activitylog/src/Traits/CausesActivity.php Lines 10 to 16 in b07e562 |
Beta Was this translation helpful? Give feedback.
-
Thank you! Sorry, I'm new to Github, I thought I should put my questions to issues. public function showLogs(Request $request, CollegeEnrollment $collegeEnrollment)
{
if(Auth::user()->can('college.enrollment.admin')) {
$collegeEnrollment->activities->load('causer');
return $collegeEnrollment->activities;
}
} Thank you so much for your help! It works now! |
Beta Was this translation helpful? Give feedback.
At first, I wonder how you've created this as an issue? The only way I've found would be that you've used the "Bug" template and removed the label? Or have you accessed https://github.com/spatie/laravel-activitylog/issues/new directly? Or is there another way GitHub does not cover with the current settings?
At all, we have several issue/discussion templates you can choose one: https://github.com/spatie/laravel-activitylog/issues/new/choose
I kindly ask you to use the correct one in the future. For the moment I've moved the issue to the "Help Discussion".
From the subject model perspective you can use the
$subject->activities
relationship.laravel-activitylog/src/Traits/LogsActivity.php