Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.
/ journalism Public archive

Record any (model or custom) events to store and review history

License

Notifications You must be signed in to change notification settings

C0deWiser/journalism

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Journalism

Record any (model or custom) events to store and review history

Service Provider

Add the package to your application service providers in config/app.php file.

'providers' => [
    
    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
    Illuminate\Auth\AuthServiceProvider::class,
    ...
    
    /**
     * Third Party Service Providers...
     */
    Codewiser\Journalism\JournalServiceProvider::class,

],

Migrations

Publish the package migrations to your application. Run these commands inside your terminal.

php artisan vendor:publish --provider="Codewiser\Journalism\JournalServiceProvider"

And also run migrations.

php artisan migrate

Using as Trait

Add Journal to you Model.

class Post extends Model {
    use Codewiser\Journalism\Traits\Journalised;
}

For now every Eloquent event will be journalized.

And you can journal any events you want.

$post = Post::first();

// Record an event
$post->journalise('my-event');

You may add to the journal record any payload you want.

$post->journalise('my-event', /* jsonable data */);

Or using as Observer

class AppServiceProvider extends ServiceProvider 
{
    public function boot()
    {
        Post::observe(Codewiser\Journalism\Observers\Journalist::class);
    }
}

Auth Subscriber

Package provides mechanism to records auth events.

class EventServiceProvider extends ServiceProvider
{
    protected $subscribe = [
        Codewiser\Journalism\Subscribers\Concierge::class,
    ];
}

Subscriber detects auth/register, auth/login, auth/logout, auth/reset-password and auth/fail events.

Custom journal records

Lets imagine, every time user wants to update the Post, he must explain, why changes were made.

class Controller
{
    public function update(Request $request, $id)
    {
        $post = Post::find($id);
        $post->journalise('comment', $request->get('comment'));
        $post->update($request->all());
    }
}

Accessing history

You have access to full history with user explanations:

foreach ($post->journal as $record) {
    echo "At {$record->created_at} 
          user {$record->user['name']} 
          makes {$record->event}\n";
    
    echo "Payload was: " . json_encode($record->payload);
}

About

Record any (model or custom) events to store and review history

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages