Change voyager model

Guilherme Pressutto picture Guilherme Pressutto · Jan 19, 2017 · Viewed 7.5k times · Source

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?

Answer

Sam picture Sam · Aug 31, 2017

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.