PHP code example of garethnic / repo

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

    

garethnic / repo example snippets


//returns with ->first()
$data = $this->model->findBy('title', $title);

//returns with ->get()
$data = $this->model->findAllBy('category', $category);

//returns with ->get()
$data = $this->model->findWhere([
            'category' => $category,
           ['year', '>' , $year],
           ['name', 'like', "%$name%"],
           ['surname', 'like', '%nes']
     ]);
     
 $data = $this->model->findWhereIn('id', [1, 2, 3])
                     ->get(['name', 'email']);
 php
IoDigital\Repo\RepoServiceProvider::class,
 bash
$ php artisan vendor:publish --provider="IoDigital\Repo\RepoServiceProvider"
 bash
$ php artisan repo:create Post
 php
$this->app->bind(
    'App\Models\Contracts\Repositories\PostRepository', // Repository (Interface)
    'App\Models\Concrete\Eloquent\EloquentPostRepository' // Eloquent (Class)
);
 php
...
use App\Models\Contracts\Repositories\PostRepository;

...

protected $model;

public function __construct(PostRepository $repo)
{
    $this->model = $repo;
}
 php
public function all($with = [], $orderBy = [], $columns = ['*']);

public function find($id, $relations = []);

public function findBy($attribute, $value, $columns = ['*']);

public function findAllBy($attribute, $value, $columns = ['*']);

public function findWhere($where, $columns = ['*'], $or = false);

public function findWhereIn($field, array $values, $columns = ['*']);

public function paginate($perPage = 25, $columns = ['*']);

public function simplePaginate($limit = null, $columns = ['*']);

public function create($attributes = []);

public function edit($id, $attributes = []);

public function delete($id);