-
Notifications
You must be signed in to change notification settings - Fork 0
Extending the user's extension
Suhayb Wardany edited this page Jul 1, 2015
·
1 revision
The best way to override/extend logic from an existing extension would be by creating a new extension and start overriding any logic you need on there.
- Create a new extension
:vendor/users - Add
platform/usersto the require array onextension.phpto ensure the the new extension is booted afterplatform/users.
Note
:vendorand:Vendorused on this page refer to your custom vendor name.
- Create a new service provider and add it to the providers array on
extension.phpand add the following code to the boot method of your new service provider. - Create a new user model. (can extend the default model)
$usersModel = get_class($this->app[':Vendor\Users\Models\User']);
$this->app['sentinel.users']->setModel($usersModel);
$this->app['sentinel.persistence']->setUsersModel($usersModel);
Overriding a controller requires re-defining the routes to point to the new controller.
- Create a new controller that extends the default controller (
Platform\Users\Controllers\Admin\UsersController) under your extensions. - Override or add new methods to your new controller.
- Redefine the routes you want to be handled by your new controller on
extension.phpand make sure to reference your new controller.
The code below will override the / routes (GET, POST) on the users extension to use the new controller.
Route::group(['namespace' => ':Vendor\Users\Controllers'], function()
{
Route::group([
'prefix' => admin_uri().'/users',
'namespace' => 'Admin',
], function()
{
Route::get('/' , ['as' => 'admin.users.all', 'uses' => 'UsersController@index']);
Route::post('/', ['as' => 'admin.users.all', 'uses' => 'UsersController@executeAction']);
});
});
Overriding repositories, event handlers or data handlers requires overriding their binding in the IoC container.
- UserRepository -
platform.users - DataHandler -
platform.users.handler.data - EventHandler -
platform.users.handler.event - Validator -
platform.users.validator
Overriding the UserRepository would require overriding the offset platform.users by adding the following code to the provider's register method of your new extension.
$this->app->bind('platform.users', ':Vendor\Users\Repositories\UserRepository');