PHP code example of kelcampus / laravel-repository

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

    

kelcampus / laravel-repository example snippets


 /**
  * Returns all records.
  * If $take is false then brings all records
  * If $paginate is true returns Paginator instance.
  *
  * @param int  $take
  * @param bool $paginate
  *
  * @return EloquentCollection|Paginator
  */
  public function getAll($take = 15, $paginate = true);

/**
 * Retrieves a record by his id
 * If $fail is true fires ModelNotFoundException. When no record is found.
 *
 * @param int     $id
 * @param bool $fail
 *
 * @return Model
 */
 public function findByID($id, $fail = true);

/**
 * @param string $column
 * @param string|null $key
 *
 * @return \Illuminate\Support\Collection|array
 */
public function lists($column, $key = null);

protected function newQuery()
{
    return app()->make($this->modelClass)->newQuery();
}

protected function doQuery($query = null, $take = 15, $paginate = true)
{
    if (is_null($query)) {
        $query = $this->newQuery();
    }

    if (true == $paginate):
        return $query->paginate($take);
    endif;

    if ($take > 0 || false != $take) {
        $query->take($take);
    }

    return $query->get();
}