1. Go to this page and download the library: Download welshdev/doctrix 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/ */
use WelshDev\Doctrix\Service\QueryBuilderService;
class MyController
{
public function index(QueryBuilderService $queryBuilder)
{
// Enhance any repository
$enhanced = $queryBuilder->for(User::class);
// Same API as inheritance approach!
$users = $enhanced->fetch(['status' => 'active']);
$paginated = $enhanced->paginate(['role' => 'admin'], 1, 20);
}
}
$repo->fetch($criteria, $orderBy, $limit, $offset) // Get multiple
$repo->fetchOne($criteria) // Get single
$repo->fetchOneOrFail($criteria, $exception) // Get or throw
$repo->fetchOneOrCreate($criteria, $values, $callback) // Get or create
$repo->updateOrCreate($criteria, $values) // Update or create
$repo->sole($criteria) // Exactly one or throw
$repo->exists($criteria) // Check if exists
$repo->doesntExist($criteria) // Check if not exists
$repo->hasExactly($count, $criteria) // Exact count
$repo->hasAtLeast($min, $criteria) // Minimum count
$repo->hasAtMost($max, $criteria) // Maximum count
$repo->chunk($size, $callback) // Process in chunks
$repo->each($callback, $chunkSize) // Process individually
$repo->lazy($chunkSize) // Generator iteration
$repo->map($callback, $chunkSize) // Transform entities
$repo->has('orders')->fetch() // Has relationship
$repo->has('orders', '>', 5)->fetch() // Count condition
$repo->doesntHave('orders')->fetch() // Missing relationship
$repo->whereHas('orders', 'status', 'pending') // Filter by related
$repo->withRelations(['orders', 'profile']) // Eager load
$repo->random($count) // Random entities
$repo->randomWhere($criteria, $count) // Random with criteria
$repo->weightedRandom(['priority' => 'ASC'], 5) // Weighted selection
use WelshDev\Doctrix\BaseRepository;
use WelshDev\Doctrix\Traits\CacheableTrait;
use WelshDev\Doctrix\Traits\SoftDeleteTrait;
class ProductRepository extends BaseRepository
{
use CacheableTrait;
use SoftDeleteTrait;
protected string $alias = 'p';
protected string $softDeleteField = 'deletedAt';
}
// Automatically excludes soft-deleted records
$products = $repo->fetch();
// Include soft-deleted records
$allProducts = $repo->fetchWithDeleted();
// Only soft-deleted records
$deletedProducts = $repo->fetchOnlyDeleted();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.