1. Go to this page and download the library: Download dees040/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/ */
dees040 / repository example snippets
namespace App\Repositories\Contracts;
use Dees040\Repository\Contracts\Repository;
interface PostRepository extends Repository
{
}
namespace App\Repositories;
use App\Post;
use App\Repositories\Contracts\PostRepository;
use Dees040\Repository\Eloquent\BaseRepository;
class PostEloquentRepository extends BaseRepository implements PostRepository
{
/**
* Get the base model.
*
* @return string
*/
public function getModel()
{
return Post::class;
}
}
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class RepositoryServiceProvider extends ServiceProvider
{
/**
* The contracts with their associated repositories.
*
* @var array
*/
protected $repositories = [
\App\Repositories\Contracts\PostRepository::class => \App\Repositories\PostEloquentRepository::class,
];
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register services.
*
* @return void
*/
public function register()
{
foreach ($this->repositories as $contract => $repository) {
$this->app->bind($contract, $repository);
}
}
}
public function __contruct(PostRepository $repostiroy)
{
$this->repository = $repostiroy;
}