-
Notifications
You must be signed in to change notification settings - Fork 114
Repositories
This feature is only available on pingpong/admin
~2.0
version (for Laravel 5).
By default, every repository
is handled by interface
and registered to the iOC
container. That's mean we can override the binder
of some instance or component
in iOC
container. For more details about iOC
container, you can read this helpful iOC documentation in Laravel Website.
Interface | Repository Class |
---|---|
Pingpong\Admin\Repositories\Users\UserRepository |
Pingpong\Admin\Repositories\Users\EloquentUserRepository |
Pingpong\Admin\Repositories\Articles\ArticleRepository |
Pingpong\Admin\Repositories\Articles\EloquentArticleRepository |
Pingpong\Admin\Repositories\Categories\CategoryRepository |
Pingpong\Admin\Repositories\Categories\EloquentCategoryRepository |
Pingpong\Admin\Repositories\Roles\RoleRepository |
Pingpong\Admin\Repositories\Roles\EloquentRoleRepository |
Pingpong\Admin\Repositories\Permissions\PermissionRepository |
Pingpong\Admin\Repositories\Permissions\EloquentPermissionRepository |
As we talk before, you can override every repository from the available repositories above. The best way to override the repository
is in a service provider class. For example, if you want to override UserRepository
. You can follow this step-by-step.
First, create a custom repository class and implement the inteface
which listed above.
// file: app/Repositories/UserRepository.php
namespace App\Repositories;
class UserRepository implements \Pingpong\Admin\Repositories\Users\UserRepository {
// your code here
}
Next, you can create a custom service provider in app/Providers
folder using make:provider
command and store the overriding script in register
method.
php artisan make:provider RepositoriesServiceProvider
// file app/Providers/RepositoriesServiceProvider
public function register()
{
$this->app->bind(
'Pingpong\Admin\Repositories\Users\UserRepository',
'App\Repositories\Users\UserRepository'
);
}
And the last, register the service provider to providers
array in config/app.php
file.
// file: config/app.php
'providers' => [
'Pingpong\Admin\AdminServiceProvider`,
// should be placed after pingpong/admin's service provider
'App\Providers\RepositoriesServiceProvider`,
]