PHP code example of dovutuan / laracom
1. Go to this page and download the library: Download dovutuan/laracom 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/ */
dovutuan / laracom example snippets
namespace App\Repositories;
use App\Models\User;
use Dovutuan\Laracom\DomRepository\BaseRepository;
class UserRepository extends BaseRepository
{
public function model(): string
{
return User::class;
}
}
namespace App\Services;
use App\Repositories\UserRepository;
class UserService
{
public function __construct(private readonly UserRepository $userRepository)
{
}
}
namespace App\Repositories;
use App\Models\User;
use Dovutuan\Laracom\DomRepository\BaseRepository;
class UserRepository extends BaseRepository
{
protected array $base_search = [
'id' => [
['column' => 'id', 'operator' => OPERATOR_EQUAL]
],
'keyword' => [
['column' => 'name', 'operator' => OPERATOR_LIKE, 'boolean' => OPERATOR_BOOLEAN_OR],
['column' => 'email', 'operator' => OPERATOR_LIKE, 'boolean' => OPERATOR_BOOLEAN_AND],
],
'name' => [
['column' => 'name', 'operator' => OPERATOR_LIKE],
]
];
public function model(): string
{
return User::class;
}
}
const OPERATOR_EQUAL = '=';
const OPERATOR_NOT_EQUAL = '<>';
const OPERATOR_LIKE = '%%';
const OPERATOR_BEFORE_LIKE = '%_';
const OPERATOR_AFTER_LIKE = '_%';
const OPERATOR_NOT_LIKE = '!%%';
const OPERATOR_GREATER = '>';
const OPERATOR_GREATER_EQUAL = '>=';
const OPERATOR_LESS = '<';
const OPERATOR_LES_EQUAL = '<=';
const OPERATOR_IN = 'in';
const OPERATOR_NOT_IN = '!in';
const OPERATOR_NULL = 'null';
const OPERATOR_NOT_NULL = '!null';
const OPERATOR_DATE = 'date';
const OPERATOR_DATE_NOT_EQUAL = '!date';
const OPERATOR_DATE_GREATER = '>date';
const OPERATOR_DATE_GREATER_EQUAL = '>=date';
const OPERATOR_DATE_LESS = '<date';
const OPERATOR_DATE_LESS_EQUAL = '<=date';
const OPERATOR_JSON = '{}';
const OPERATOR_JSON_NOT_CONTAIN = '!{}';
const OPERATOR_BOOLEAN_AND = 'and';
const OPERATOR_BOOLEAN_OR = 'or';
$user = $this->userRepository->find(123);
$user = $this->userRepository->findByConditions(['id' => 123]);
$user = $this->userRepository->create(Input::all());
$user = $this->userRepository->update(123, Input::all());
$user = $this->userRepository->updateByConditions(['id' => 123], Input::all());
$user = $this->userRepository->delete(123);
$user = $this->userRepository->deleteByConditions(['id' => 123]);
$user = $this->userRepository->count(['id' => 123]);
$user = $this->userRepository->paginate(['id' => 123]);
$user = $this->userRepository->all(['id' => 123]);
$user = $this->userRepository->inserrt([['name' => 'Hello'], ['name' => 'Hi']]);
$user = $this->userRepository->updateOrCreate(['id' => 123], ['name' => 'Hello']);
$user = $this->userRepository->update(['id' => 123, 'name' => 'Hello'], ['id'], ['name']);
$user = $this->userRepository->allAndPluck('name', 'id', ['id' => 123]);
shell
php artisan vendor:publish --tag=laracom
terminal
php artisan make:repository UserRepository
terminal
php artisan make:repository UserRepository --ser
terminal
php artisan make:service UserService
terminal
php artisan make:service UserService --repo