1. Go to this page and download the library: Download derakht/repository-pattern 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/ */
derakht / repository-pattern example snippets
namespace App\Http\Controllers;
use App\Repositories\Contract\PostRepositoryInterface;
class PostController extends Controller
{
public $postRepository;
public function __construct()
{
$this->postRepository = app(PostRepositoryInterface::class);
}
public function index()
{
return $this->postRepository->all();
}
}
namespace App\Http\Controllers;
use App\Repositories\Contract\PostRepositoryInterface;
class ReportController extends Controller
{
public $postRepository;
public function __construct(PostRepositoryInterface $postRepository)
{
$this->postRepository = $postRepository;
}
public function index()
{
return $this->postRepository->all();
}
}