PHP code example of hpolthof / repository

1. Go to this page and download the library: Download hpolthof/repository 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/ */

    

hpolthof / repository example snippets


interface RepositoryInterface
{
    public function all(array $columns = ['*']): Collection;
    public function list(string $orderByColumn, string $orderBy = 'desc', array $with = [], array $columns = ['*']): Collection;
    public function builder(Closure $builder, array $columns = ['*']): Collection;

    public function create(array $data): ?Model;
    public function update(array $data, $id): bool;
    public function delete($id): bool;

    public function find($id, array $columns = ['*']): ?Model;
    public function findBy(string $field, $value, array $columns = ['*']): ?Model;
}

use App\Demo;

class DemoRepository extends Repository {
    protected $modelName = Demo::class;
}

class DemoController extends Controller {
    protected $repository;
    
    public function __construct(DemoRepository $repository)
    {
        $this->repository = $repository;
    }
}
bash
php artisan make:repository {modelName}