PHP code example of skore-labs / laravel-auditable
1. Go to this page and download the library: Download skore-labs/laravel-auditable 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/ */
skore-labs / laravel-auditable example snippets
namespace SkoreLabs\LaravelAuditable\Tests\Fixtures;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use SkoreLabs\LaravelAuditable\Traits\Auditable;
class Post extends Model
{
use Auditable;
// Add this one and it will auto-detect for the deletedBy
// use SoftDeletes;
/**
* The attributes that should be visible in serialization.
*
* @var array
*/
protected $visible = ['title', 'content'];
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePostsTestTable extends Migration
{
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title');
$table->text('content');
$table->timestamps();
$table->softDeletes();
$table->auditables();
// or if has softDeletes (deleted_at column):
$table->auditables(true);
// also you might want to rename the users table:
$table->auditables(true, 'my_users_table');
});
}
public function down()
{
Schema::dropIfExists('posts');
}
}
public function down()
{
Schema::table('posts', function (Blueprint $table) {
$table->dropAuditables();
// or if has softDeletes (deleted_at column):
$table->dropAuditables(true);
});
}
$post = Post::first();
$post->createdBy; // Author of the post
$post->updatedBy; // Author of the last update of the post
$post->deletedBy; // Author of the deletion of the post
$post->author; // Alias for createdBy
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.