Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change voyager model

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?

like image 389
Guilherme Pressutto Avatar asked Oct 18 '25 15:10

Guilherme Pressutto


1 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.

like image 104
Sam Avatar answered Oct 20 '25 17:10

Sam