PHP code example of tgalfa / reposervice

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

    

tgalfa / reposervice example snippets


return [
    ...
    'namespaces' => [
        ....
        'repositories' => 'App\Repositories',
        'repositoryContracts' => 'App\Repositories\Contracts',

        'services' => 'App\Services',
        'serviceContracts' => 'App\Services\Contracts',
        ....
    ],
    ....
    'paths' => [
        'repositories' => 'app/Repositories/',
        'repositoryContracts' => 'app/Repositories/Contracts/',

        'services' => 'app/Services/',
        'serviceContracts' => 'app/Services/Contracts/',
    ],
    ....
];

return [
    ...
    'namespaces' => [
        ....
        'main' => [
            'repository' => 'App\Repositories',
            'repositoryContract' => 'App\Repositories\Contracts',

            'service' => 'App\Services',
            'serviceContract' => 'App\Services\Contracts',
        ],
    ],
    ....
    'main' => [
        'repository' => 'MyAbstractMainRepository',
        'repositoryContract' => 'MyMainRepositoryInterface',

        'service' => 'MyAbstractMainService',
        'serviceContract' => 'MyMainServiceInterface',
    ],
];

    public function getModel();

    public function get(array $columns = ['*'], array $scopes = []]);

    public function paginate(
        int $perPage,
        array $columns = ['*'],
        array $scopes = []
    );

    public function getById(int $id, array $columns = ['*']);

    public function store(array $data, array $scopes = []);

    public function update(Model $model, array $data, array $scopes = []);

    public function updateOrCreate(array $attributes, array $data, array $scopes = []);

    public function delete(Model $model);

$post = $this->postService->get(
    ['id', 'title', 'description'],
    ['isActive', 'byCategory' => 5]
);

public function scopeIsActive(Builder $query)
{
    return $query->where('active', 1);
}
public function scopeByCategory(Builder $query, int $categoryId)
{
    return $query->where('category_id', $categoryId);
}

$post = $this->postService->paginate(
    8,
    ['id', 'title', 'description'],
);

$post = $this->postService->store($request->all());

$post = $this->postService->update($post, $request->all());

$post = $this->postService->updateOrCreate(
    ['slug' => $request->slug],
    $request->all()
);

$post = $this->postService->delete($post);

    public function getModel();

    public function get(
        array $columns = ['*'],
        array $scopes = [],
        int $perPage = null
    );

    public function paginate(
        int $perPage,
        array $columns = ['*'],
        array $scopes = []
    );

    public function getById(int $id, array $columns = ['*']);

    public function store(array $data);

    public function update(Model $model, array $data);

    public function updateOrCreate(array $attributes, array $data);

    public function delete(Model $model);
bash
php artisan vendor:publish --tag="reposervice-config"
 bash
php artisan reposervice:generate Post