Activity Log

Open
Vanguard - Advanced PHP Login and User Management Vanguard - Advanced PHP Login and User Management July 08, 2018
Login to reply
Joshua Blevins
1 year ago

Is this the same for the newer versions?

Milos Stojanovic Support Agent
5 years ago

Hey Joshua,

The log message is just a string and you can customize it however you want. Here is an example:

$name = "John Doe";
$yearsOld = 28;
app(\Vanguard\Services\Logging\UserActivity\Logger::class)->log( "The customer's name is {$name} and he is {$years} old." );

Milos

Joshua Blevins
5 years ago


    public function edit($id)

    {

         $edit= true;

        

        $brs = BadRunSheet::find($id);

        $employees = Employee::select('last_name', 'first_name', 'user_id')->orderBy('last_name')->get();

        

         app(\Vanguard\Services\Logging\UserActivity\Logger::class)->log('Bad run sheet ');

        

        return view('badrunsheets.edit', compact('brs', 'employees', 'edit'));

    }


on on a controller with the activity log how would I go about adding A variable to be logged. For example if I hit edit on line x the system would log (user) has opened edit on incident (number from row).



Milos Stojanovic Support Agent
5 years ago
Closed due to inactivity.
Milos Stojanovic Support Agent
5 years ago

Hey Joshua,

There is no official tutorial on how to do that, but I will add it soon for sure.

In general, you will need to either fire an event and then create a listener or subscriber which will listen for that event and then log the message. Check "app/Listeners/UserEventsSubscriber.php" file to see it in action.

Now, if you don't want to follow that approach, you can simply use the code below anywhere in your controller to log a specific action:

app(\Vanguard\Services\Logging\UserActivity\Logger::class)->log('Your custom log message here');

This will automatically write the log message you provide into the activity log for currently authenticated user.

- Milos

Joshua Blevins
5 years ago

Is there a tutorial on how to add other tables to the activity log.

For example I have another table called companies. Is there a way to add when someone edits a company or adds a new company to add it into the activity log