<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
timwassenburg / laravel-repository-generator example snippets
namespace App\Http\Controllers;
use App\Repositories\UserRepositoryInterface;
class UserController extends Controller
{
private $user;
public function __construct(UserRepositoryInterface $userRepository)
{
$this->user = $userRepository;
}
// your controller functions
}
public function index()
{
return $this->user->all();
}
artisan make:provider RepositoryServiceProvider
namespace App\Providers;
use App\Repositories\Eloquent\UserRepository;
use App\Repositories\UserRepositoryInterface;
use Illuminate\Support\ServiceProvider;
/**
* Class RepositoryServiceProvider
* @package App\Providers
*/
class RepositoryServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->app->bind(UserRepositoryInterface::class, UserRepository::class);
}
}