2017 © Pedro Peláez
 

library lara-service

Service layer for CRUD

image

omnicode/lara-service

Service layer for CRUD

  • Tuesday, June 19, 2018
  • by omnicode
  • Repository
  • 1 Watchers
  • 0 Stars
  • 301 Installations
  • PHP
  • 1 Dependents
  • 3 Suggesters
  • 0 Forks
  • 0 Open issues
  • 15 Versions
  • 238 % Grown

The README.md

Build Status Total Downloads Latest Stable Version License , (*1)

Lara-Service

Generalized Service layer, (*2)

Installation

Run the following command from you terminal:, (*3)

bash composer require "omnicode/lara-service: 2.0.*", (*4)

or add this to require section in your composer.json file:, (*5)

"omnicode/lara-service": "2.0.*", (*6)

then run composer update, (*7)

Usage

First, create your Service class like shown below with example AcccountService, (*8)

<?php

namespace App\Services;

use App\Repositories\Contracts\AccountRepositoryInterface as AccountRepository;
use App\Validators\AccountValidator;
use LaraService\Services\LaraService;

class AccountService extends LaraService
{
    public function __construct(AccountRepository $accountRepository, AccountValidator $accountValidator)
    {
        $this->baseRepository = $accountRepository;
        $this->baseValidator = $accountValidator;
    }
}

The Repository and Validator classes should have the following methods pushCriteria, saveAssociated, findForShow, findFillable, getKeyName, destroy, getIndexableColumns, paginate, setSortingOptions and isValid, getErrors respectively. Those are already implemented in Lara Validation and Lara Repository packages., (*9)

And finally, use the service in the controller:, (*10)

<?php

namespace App\Http\Controllers;

use App\Services\AccountService;

class AccountsController extends Controller
{   
    public function __construct(AccountService $accountService)
    {
        parent::__construct();
        $this->baseService = $accountService;
    }
}

Available Methods

The following methods are available in LaraService:, (*11)

LaraRepo\Contracts\RepositoryInterface
    public function setBaseRepository(RepositoryInterface $repository)
    public function getBaseRepository()
    public function setBaseValidator($validator)
    public function getBaseValidator ()
    public function setValidationErrors($errors)
    public function getValidationErrors()
    public function paginate($sort = [], $group = self::GROUP)
    public function create($data)
    public function createWithRelations($data, $relations = null)
    public function findForShow($id, $columns = null)
    public function find($id)
    public function update($id, $data)
    public function updateWithRelations($id, $data, $relations = null)
    public function destroy($id)
    public function validate($validator, $data, $options = [])
    public function paginateRepositoryWhere($repository, $group = self::GROUP, $column = null, $val = null)
    public function paginateRepository($repository, $group = self::GROUP)
    public function setSortingOptions($repository, $options = [], $group = self::GROUP)
}

Example - create a new account repository:, (*12)


// for index page use // returns item list and columns with their columns information $this->accountService->paginate() // if you want to sort your index page use $this->accountService->setSortingOptions($repository) // to create new record $this->accountService->create($request->all()); // returns validation errors of last operation $this->accountService->getValidationErrors(); // to save items with relations $this->accountService->createWithRelations($data, $relations) // to find based on $showable attributes $this->accountService->findForShow($id) // usual find with fillable columns $this->accountService->find($id) // to update based on primary key $this->accountService->update($id, $data) // to update and item with relations $this->accountService->updateWithRelations($id, $data, $relations) // to delelte $this->accountService->destroy($id) // to validate the data (internally uses the injected Validator) $this->accountService->validate($validator, $data, $options = [])

The Versions

19/06 2018

v3.0.x-dev

3.0.9999999.9999999-dev

Service layer for CRUD

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar omnicode

laravel crud service layer

19/06 2018
04/06 2018

3.0.1

3.0.1.0

Service layer for CRUD

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar omnicode

laravel crud service layer

23/02 2018

v0.x-dev

0.9999999.9999999.9999999-dev

Service layer for CRUD

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar omnicode

laravel crud service layer

23/02 2018

v1.x-dev

1.9999999.9999999.9999999-dev

Service layer for CRUD

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar omnicode

laravel crud service layer

23/02 2018
22/02 2018

2.0.0

2.0.0.0

Service layer for CRUD

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar omnicode

laravel crud service layer

20/02 2018

0.0.8

0.0.8.0

Service layer for CRUD

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar omnicode

laravel crud service layer

20/02 2018

0.0.7

0.0.7.0

Service layer for CRUD

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar omnicode

laravel crud service layer

20/02 2018

1.0.7

1.0.7.0

Service layer for CRUD

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar omnicode

laravel crud service layer

19/02 2018

0.0.6

0.0.6.0

Service layer for CRUD

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar omnicode

laravel crud service layer

13/02 2018

0.0.4

0.0.4.0

Service layer for CRUD

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar omnicode

laravel crud service layer

26/01 2018

0.0.2

0.0.2.0

Service layer for CRUD

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar omnicode

laravel crud service layer

26/01 2018

0.0.1

0.0.1.0

Service layer for CRUD

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar omnicode

laravel crud service layer