1. Go to this page and download the library: Download kuroragi/general-helper 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/ */
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->timestamps();
$table->softDeletes();
$table->blameable(); // adds all three columns with FK to users
});
use Kuroragi\GeneralHelper\Traits\Blameable;
class Post extends Model
{
use Blameable;
}
$post->createdBy; // User
$post->updatedBy; // User
$post->deletedBy; // User
$table->blameable(); // created_by, updated_by, deleted_by (FK to 'users')
$table->blameable('admins'); // FK to custom table
$table->blameable(null, false); // no FK constraint
$table->createdBy();
$table->updatedBy();
$table->deletedBy();
$table->dropBlameable('posts'); // drop columns + FK
Post::createdBy($userId)->get();
Post::updatedBy($userId)->get();
Post::deletedBy($userId)->get();
Post::createdBy()->get(); // defaults to Auth::id()