1. Go to this page and download the library: Download sysbox/laravel-base-entity 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/ */
sysbox / laravel-base-entity example snippets
class User extend BaseModel implements UserReferable <<<<<<<<< implement this interface
{
/**
* @return mixed <<<<<<<<< add this function
*/
public function getUserId()
{
return $this->id;
}
/**
* @return \Illuminate\Contracts\Auth\Authenticatable|UserReferable|null
*/
public static function getCurrentUser() <<<<<<<<< add this function
{
return Auth::user();
}
}
return [
// this is the user class that will be refer to for fields: created_by_id and updated_by_id
'user_class' => User::class, <<<<<<<<< add user class here.
// this is the system user's id,
// leave it BLANK for auto generation.
// or specifiy in env, ie: 'system_user_id' => env('SYSTEM_USER_ID'),
'system_user_id' => '',
];
use Sysbox\LaravelBaseEntity\BaseModel;
class Person extend BaseModel <<<<<<<<< extend your BaseModel
{
// all other laravel function for the model..
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Sysbox\LaravelBaseEntity\Facades\LaravelBaseEntity;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
LaravelBaseEntity::addBasicLaravelBaseEntityColumns($table);
$table->string('name');
//or add column
// LaravelBaseEntity::addHashIdColumn($table, 'another_user_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}