I want to add some mutators on Voyager's User class, but I won't change anything inside vendor folder, and Voyages uses a User model inside the package. Is it possible for me to, somehow, change this?
-
1Never touch `vendor` because once you touch `Composer` etc. your changes won't be reflected. Also `vendor` should be always `.gitignore` so you won't be able to save your work into repo. – Matt Komarnicki Jan 19 '17 at 23:56
-
updated my answer – aimme Jan 20 '17 at 01:17
2 Answers
Simple enough. Modify the default Laravel User model to
<?php
namespace App\Models;
use TCG\Voyager\Models\User as VoyagerUser;
class User extends VoyagerUser {
// add custom mutators and other code in here
}
Then you can update app/config/voyager.php
as @aimme said and have it as
'user' => [
'add_default_role_on_register' => true,
'default_role' => 'user',
'admin_permission' => 'browse_admin',
'namespace' => App\User::class,
],
This way you bring in the power of Voyager's User model to your own with no hackery involved.

- 2,540
- 2
- 23
- 24
-
I'm yet to extend Roles & Permissions, but I don't see why it wouldn't work. I extended the `VoyagerBreadController` to get some custom functionality going. You might want to give Voyager BREAD [Policies](https://laravel.com/docs/5.5/authorization#creating-policies) a look in the upcoming v1.0 release before extending Voyager's roles & permissions though, as they may help you achieve the same effect. – Sam Sep 06 '17 at 07:28
-
Interesting. Is there any news you can point me to for a release date for v1.0? – WhyAyala Sep 06 '17 at 18:13
-
-
1Please note that the `namespace` option in the `user` config of `app/config/voyager.php` is now deprecated in favour of the default user model entry in `app/config/auth.php` – Damilola Olowookere Dec 11 '19 at 09:45
For most cases extending the vendor packages works fine.
Update voyager configuration
See config/voyager.php
change user array like this. i have changed only namespace
here,from voyager user tp App\User.
'user' => [
'add_default_role_on_register' => true,
'default_role' => 'user',
'admin_permission' => 'browse_admin',
'namespace' => App\User::class,
],
but to bring additional changes you could try following way.
Loading whole voyager package as a local package.
Warning: After doing this the package would no longer be a vendor package.
To do that
1 - create a packages folder on the root of the project.
2 - clone the tcg/voyager repo into the packages folder or cut paste vendor tcg folder into packages folder that you created. so you will be having your directories like this yourproject/packages/tcg/voyager
. if you have required tcg/voyager in composer.json remove it from there.
3 - update composer.json file on the root of your project. add TCG\\Voyager
autoload. see below sample, added the line inside psr-4.
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"TCG\\Voyager\\": "packages/tcg/voyager/src/"
}
},
4 - run composer update
sometimes you might have to do composer dump-autoload
after bringing changes to the packages.

- 6,385
- 7
- 48
- 65