PHP code example of aleprosli / repository-pattern
1. Go to this page and download the library: Download aleprosli/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/ */
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class RepositoryServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind('App\Repositories\UserRepositoryInterface','App\Repositories\UserRepository');
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Repositories\UserRepositoryInterface;
class UserController extends Controller
{
private $user;
public function __construct(UserRepositoryInterface $user)
{
$this->user = $user;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$users = $this->user->all();
dd($users);
}
}