Laravel activitylog, error in implementation

Asked

Viewed 144 times

0

I’m following the documentation of the site: https://docs.spatie.be/laravel-activitylog/v2/basic-usage/logging-activity, but I’m not able to implement the option below:

Setting a You can specify on which Object the Activity is performed by using performedOn:

activity()
   ->performedOn($someContentModel)
   ->log('edited');

$lastActivity = Activity::all()->last(); //returns the last logged activity

$lastActivity->subject; //returns the model that was passed to `performedOn`;
The performedOn-function has a shorter alias name: on

When I try to pass the parameters in the controller it generates error in performedOn($someContentModel), would like to know what should I use instead of the $someContentModel variable.

1 answer

1

You should use the "return" of a MODEL of yours.. ex:

$someContentModel = User::first();
  • It worked, I was passing the parameter ::all() so it didn’t work. Thanks friend!

  • Not to impose, but do you know how you use the -> Using the Causesactivity trait documentation? I’m not able to implement it, I believe it serves to monitor what each user did in the log system, it would be very useful.

  • You call l Trait inside your MODEL it gives the example here https://docs.spatie.be/laravel-activitylog/v2/advanced-usage/logging-model-events#ignoring-Attributes-from-logging

Browser other questions tagged

You are not signed in. Login or sign up in order to post.