PHP code example of codewiser / journalism

1. Go to this page and download the library: Download codewiser/journalism library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codewiser / journalism example snippets


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

],

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

$post = Post::first();

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

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

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

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

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

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);
}