Git Product home page Git Product logo

activitylog's Introduction

ActivityLog

A simple and clean Laravel 5 activity logger for monitoring user activity on a website or web application.

Installation

Basic installation, service provider registration, and aliasing:

To install ActivityLog, make sure "regulus/activity-log" has been added to Laravel 5's composer.json file.

"require": {
	"regulus/activity-log": "0.6.*"
},

Then run php composer.phar update from the command line. Composer will install the ActivityLog package. Now, all you have to do is register the service provider and set up ActivityLog's alias. In app/config/app.php, add this to the providers array:

Regulus\ActivityLog\ActivityLogServiceProvider::class,

And add this to the aliases array:

'Activity' => Regulus\ActivityLog\Models\Activity::class,

Publishing migrations and configuration:

To publish this package's configuration and migrations, run this from the command line:

php artisan vendor:publish

You will now be able to edit the config file in config/log.php if you wish to customize the configuration of ActivityLog.

Note: Migrations are only published; remember to run them when ready.

To run migration to create ActivityLog's table, run this from the command line:

php artisan migrate

Basic Usage

Logging user activity:

	Activity::log([
		'contentId'   => $user->id,
		'contentType' => 'User',
		'action'      => 'Create',
		'description' => 'Created a User',
		'details'     => 'Username: '.$user->username,
		'updated'     => (bool) $id,
	]);

The above code will log an activity for the currently logged in user. The IP address will automatically be saved as well and the developer flag will be set if the user has a developer session variable set to true. This can be used to differentiate activities between the developer and the website administrator. The updated boolean, if set to true, will replace all instances of "Create" or "Add" with "Update" in the description and details fields.

Advanced Usage

As of version 0.6.0, ActivityLog has built in the ability to dynamically create descriptions based on language keys in Laravel's language files. If you would like to enable this feature without having to set language_key to true when you use the log() function, change defaults.language_key to true in the config file (it is not present by default so you will have to add it).

Logging user activity with language keys:

	Activity::log([
		'contentType' => 'Record',
		'description' => [
			'created_items', [ // "activity-log::descriptions.created_items" is ":user created :number :items."
				'number' => 2,
				'items'  => 'SPL|labels.record', // "labels.record" in this example has a string of "Record|Records"
			],
		],
		'details' => [
			'record',
			'This is Some Kind of Record',
		],
		'data' => [
			'category' => 'Content',
		],
	]);

	echo $activity->getDescription(); // may output "Unknown User created 2 records."

	echo $activity->getDetails(); // may output "Record: This is Some Kind of Record"

	echo $activity->getData('category'); // will output "Content"

In the example above, the items replacement variable in the description has a number of specified properties before the | character which separates them from the actual language variable. The available properties are as follows:

S - Return the "singular" string (in the case of "labels.record", "Record")
P - Return the "plural" string (in the case of "labels.record", "Records")
A - Prepend the string with "a" or "an" (example: "a record" instead of just "record")
L - Convert the string to lowercase

In our example above, you will see both singular ("S") and plural ("P") are being used. When both are used, the description builder looks for a number replacement variable to decide whether the singular or plural form should be used.

Note: The user replacement variable is automatically set based on the record's user ID.

Getting Linked Content

Set up the content_types config array like the following example:

	'item' => [
		'uri'       => 'view/:id',
		'subdomain' => 'items',
		'model'     => 'App\Models\Item',
	],

You can use getContentItem() to get the item based on the specified model (assuming, in the case of the above specified example, that your content type is set to "Item"). You can also use getUrl() to get the URL of the content item or getLinkedDescription() to get a linked description for the item.

Displaying Action Icons

Display an action icon based on config setup:

	echo $activity->getIconMarkup();

You can also use getIcon() to get just the icon class from which to build your own icon markup.

activitylog's People

Contributors

danikp avatar dansup avatar dimamarkus avatar evias avatar moura137 avatar regulus343 avatar syphernl avatar thujohn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

activitylog's Issues

preg_replace(): Parameter mismatch, pattern is a string while replacement is an array

this is the example in readme i tried to run and test but it failed with issue title error.

Activity::log([
'contentType' => 'Record',
'description' => [
'created_items', [ // "activity-log::descriptions.created_items" is ":user created :number :items."
'number' => 2,
'items' => 'SPL|labels.record', // "labels.record" in this example has a string of "Record|Records"
],
],
'details' => [
'record',
'This is Some Kind of Record',
],
'data' => [
'category' => 'Content',
],
]);

error con laravel 6

la librería me da este error con laravel 6

call_user_func() expects parameter 1 to be a valid callback, no array or string given
revisando la libreria veo que en el fichero Activity.php la linea donde falla es esta:
$user = call_user_func(config('log.auth_method'));
y no se muy bien para que se está utilizando esa llamada, de hecho he probado a comentar la linea
y el resto del paquete funciona correctamente.
Tengo que añadir alguna configuración en alguno de mis ficheros para no salte ese error?

[english]
the library gives me this error with laravel 6

call_user_func () expects parameter 1 to be a valid callback, no array or string given
Checking the library I see that in the Activity.php file the line where it fails is this:
$ user = call_user_func (config ('log.auth_method'));
and I don't know very well what that call is being used for, in fact I have tried to comment out the line
and the rest of the package works fine.
Do I have to add some configuration in any of my files so I don't get that error?

Use ActivityLog with Mongo DB

Hi

To use ActivityLog with Mongo DB, we need to call Jessengers instead of standart Eloquent in Model

I don't really know the way to do, so I create a Fork of your repo and make the modification in a branch.

Regards
Nicolas

problem with install

when i install this package i see error that refer to : ActivityLogServiceProvider.php and there isn't any folder named lang/vendor/activity-log, what can i do?

Log set properties

Hello I am creating a log but would like to manually set the properties. How do I do this?

activity("search")->log(['properties' => 'search criteria goes here']);

Thanks

I wish there was an activity type field

Just for some extra flexibility, I wish for a activity type field that is just a string with no rules. The activity type could allow developers to attach icons to their feed or categorize activity.

$this->user is null

I'm trying to access the name of the user but the $this->user inside the Activity model is always null. Why?

best practice to use this package

hi
i really like your package it is very useful, i'd like to use it for my elequent events, but i have one question what is the best way to this ? should i do this in every single of my models or there is a better approach to this ?

description language not being replaced.

I'm using the latest version of your package

"regulus/activity-log": "^0.6.7"

I've set the replacement prefixes to default to "labels" and create a "labels.php" language file with the respective keys

and when language_key is to true when passing the params

return [
        'contentId' => $model->id,
        'contentType'=> $model->getTable(),
        'action'=> $action,
        'updated' => ($action === 'update'),
        'developer' => 0,
        'description' => [
          'updated_item', [
            'user' => auth()->user()->name,
            'item' => 'SPAL|labels.claims'
          ]
        ]
      ];

I get the following record entry

id, user_id, content_type, content_id, action, description, details, data, language_key, public, developer, ip_address, user_agent, created_at, updated_at
'9', '12', 'claims', '11', 'Update', '["updated_item",{"user":"zmayer_distributor","item":"SPAL|labels.claims"}]', NULL, NULL, '1', '1', '0', '192.168.10.10', 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0', '2017-03-01 22:40:56', '2017-03-01 22:40:56'

Is this how the content for the description field should look like or am I missing something?

Adding unique model identifier to activity log table

There could be cases where I just want to retrieve activity log for a particular model Id.

It would be good to have that column in the table. Using which I can get activity logs for that particular id or array of ids.

What should be done if I want to write logs from jobs?

In my application, it's been excessively used. So, I want to move the calls to your Activity::log calls from controllers to a job. But if it's been done inside a job, then the ip_address + user_agent data won't be valid. How can I achieve the same as from controllers within the jobs?

call_user_func Error

Laravel Framework version 5.1.26 (LTS)

ErrorException (E_WARNING)
HELP
call_user_func() expects parameter 1 to be a valid callback, no array or string given

In /model/Activity.log
when i replace this line.
$user = call_user_func(config('log.auth_method'));
By this,
$user = config('log.auth_method');

It works.
But let me know whether its right ?.

composer version not matching repo

Hi!

We are upgrading our Laravel version from 5.0.* to 5.1.*, and in the github repo the latest version of ActivityLog requires 5.1; but the last regular version (so not dev-master) still requires 5.0.*.

Could you create a new 0.5.3 tag that includes this update? We are now using the dev-master version but that does not seem ideal :)

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.