PHP code example of thoth-pharaoh / base-model-repository

1. Go to this page and download the library: Download thoth-pharaoh/base-model-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/ */

    

thoth-pharaoh / base-model-repository example snippets

bash
namespace App\Repositories;

use App\Models\Blog;
use Pharaoh\BaseModelRepository\Repositories\AbstractBaseRepository;

class BlogRepository extends AbstractBaseRepository
{
    public function __construct(Blog $blog)
    {
        $this->model = $blog;
        $this->table = $this->model->getTable();
    }
}
bash
$repository->getAll($fields, $eagerLoad);
bash
$repository->getByWhereIn($whereField, $whereValue, $field, $eagerLoad);
bash
$repository->find($id, $eagerLoad);
bash
$repository->findByWhere($where, $field, $eagerLoad);
bash
$repository->findWriteConnect($id);
bash
$repository->findWriteConnectByLockForUpdate($id);
bash
$repository->findDuplicateValue($field, $where, $extraParameters, $havingCount)
bash
$repository->update($id, $parameters)
bash
$repository->updateMuti($data, $parameters, $field)
bash
$repository->increment($where, $field, $num)
bash
$repository->decrement($where, $field, $num)
bash
use Illuminate\Database\Eloquent\Builder;

/**
 * 篩選 交易時間
 *
 * @param Builder $builder
 */
protected function addDate(Builder $builder)
{
    $builder->macro('date', function (Builder $builder, array $params) {
        // 實作過濾條件的內容部分
        $date = Arr::get($params, 'date');

        return $builder->where('date', $date);
    });
}
bash
$builder = $this->scopeQuery($scope, $params, $model)
bash
$builder = $this->scopeQuery(OrderScope::class, ['date' => '2022-01-10'])
  ->select('*')