PHP code example of vdhoangson / laravel-repository

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

    

vdhoangson / laravel-repository example snippets


interface ExampleRepositoryInterface extends BaseInterface
{}

class ExampleRepository extends BaseRepository implements ExampleRepositoryInterface
{
    /**
     * Model entity class that will be use in repository
     *
     * @return BaseInterface
     */
    public function entity(): string
    {
        return Example::class;
    }

}

class ExampleController extends Controller {

    /**
     * @var ExampleRepositoryInterface $exampleRepository
     */
    protected $exampleRepository;

    public function __construct(ExampleRepositorynterface $exampleRepository){
        $this->exampleRepository = $exampleRepository;
    }

    ....
}

$this->repository->skipCache()->findWhere(...)

$data = $this->repository->scopeQuery(function($query){
    return $query->orderBy('sort_order','asc');
})->all();