1. Go to this page and download the library: Download peak/database 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/ */
namespace {
use Peak\Database\Common\LaravelPhinxMigration;
use Peak\Database\Laravel\LaravelDatabaseService;
use Peak\Database\Laravel\LaravelConnectionManager;
use Peak\Database\Phinx\PhinxConfigService;
use Peak\Database\Phinx\PhinxEnvConfig;
sername' => $env['DB_USERNAME'],
'password' => $env['DB_PASSWORD'],
'charset' => $env['DB_CHARSET'],
'collation' => $env['DB_COLLATION'],
'prefix' => $env['DB_PREFIX'],
], 'connectionName');
LaravelConnectionManager::setConnection($db, 'prod');
return (new PhinxConfigService())
->create(
'migrations',
LaravelPhinxMigration::class,
'migrations',
'prod',
[
new PhinxEnvConfig('prod', [
'name' => $db->getDatabaseName(),
'connection' => $db->getPdo(),
])
]
);
} catch(\Exception $e) {
die($e->getMessage());
}
}
use Peak\Database\Laravel\LaravelPhinxMigration;
use Illuminate\Database\Schema\Blueprint;
class Users extends LaravelPhinxMigration
{
public function up()
{
$this->db->getSchemaBuilder()->create('users', function(Blueprint $table){
$table->increments('id');
$table->string('username')->unique();
$table->string('email')->unique();
$table->string('password');
$this->tsColumns($table);
$table->timestamp('lastSeen')->nullable()->default(null);
});
}
public function down()
{
$this->db->getSchemaBuilder()->drop('users');
}
}
namespace Domain\UseCase;
use Peak\Database\Generic\QueryFiltersInterface;
use Peak\Database\Generic\QueryPaginationInterface;
class MyUseCase
{
// ...
public function execute(
QueryFiltersInterface $queryFilters,
QueryPaginationInterface $queryPagination
) {
// do things
// ...
return $this->repository->getMany($queryFilters, $queryPagination);
}
}
use Domain\Repository\MyRepositoryInterface;
use Peak\Database\Generic\QueryFiltersInterface;
use Peak\Database\Generic\QueryPaginationInterface;
use Peak\Database\Common\LaravelGenericHelper;
class MyRepository implements MyRepositoryInterface
{
// ...
public function getMany(
QueryFiltersInterface $queryFilters,
QueryPaginationInterface $queryPagination
) {
$qb = $this->table('tusers');
$qb = LaravelGenericHelper::filterQuery($qb, $queryFilters);
$qb = LaravelGenericHelper::paginateQuery($qb, $queryPagination);
return $qb->get();
}
}
class UserPagination extends AbstractRestrictedQueryPagination
{
protected $allowedColumns = [
'username', 'email', 'createdAt', 'updatedAt', 'deletedAt'
];
protected $allowedDirections = [
'asc', 'desc'
];
}
// and use it like this:
$queryPagination = new UserPagination(
$column,
$direction,
$pageNumber,
$itemsPerPages
);
class UserFilters extends AbstractRestrictedQueryFilters
{
protected $allowedColumns = [
'username', 'email', 'createdAt', 'updatedAt', 'deletedAt'
];
protected $allowedOperators = [
'=', '>', '<', 'like'
];
}
// and use it like this:
$queryFilters = new UserFilters();
$queryFilters
->where('username', 'bob', '=')
//...
phinx.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.