PHP code example of thombas / revised-repository-pattern
1. Go to this page and download the library: Download thombas/revised-repository-pattern 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/ */
thombas / revised-repository-pattern example snippets
use Thombas\RevisedRepositoryPattern\Traits\ImplementsRevisedRepositoryPattern;
class User extends Model
{
use ImplementsRevisedRepositoryPattern;
}
public function __invoke(): mixed
{
$this->model->create([
'first_name' => 'Thomas',
'last_name' => 'Fielding',
]);
}
public function __construct(
public Model $model,
public string $firstName,
public string $lastName,
) {
parent::__construct(model: $model);
}
public function __invoke(): mixed
{
$this->model->create([
'first_name' => $this->firstName,
'last_name' => $this->lastName,
]);
}
public function __invoke(): EloquentBuilder|QueryBuilder
{
return $this->model
->query()
->where('first_name', 'Thomas');
}
public function __construct(
public Model $model,
public string $firstName,
public string $lastName,
) {
parent::__construct(model: $model);
}
public function __invoke(): mixed
{
return $this->model
->query()
->where('first_name', $this->firstName)
->where('last_name', $this->lastName);
}
public function __construct(
public string $firstName,
public string $lastName,
) {
parent::__construct(model: null);
}
public function __invoke(): mixed
{
return User::query()
->where('first_name', $this->firstName)
->where('last_name', $this->lastName);
}