baum icon indicating copy to clipboard operation
baum copied to clipboard

Why don't use Trait?

Open ab0029 opened this issue 9 years ago • 3 comments

I think Trait extended model is more usefull. Just like softDelte. Is anyone agree

ab0029 avatar Jun 24 '16 07:06 ab0029

trait is only useful if you are trying to expose some helper methods into the class,

but as for Baum's case, it's more than that... Baum uses polymorphism.

you can't detect if the class is using a trait using instanceof, but there are non-conventional ways to detect it.

WisdomSky avatar Jul 20 '16 09:07 WisdomSky

The problem is now I cant use this package with my User model that alredy extends Authenticable

MichaelObi avatar Oct 01 '16 17:10 MichaelObi

@MichaelObi, I had the same problem and solved it that way:

Take a look at this file: /vendor/laravel/framework/src/Illuminate/Foundation/Auth/User.php

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements
    AuthenticatableContract,
    AuthorizableContract,
    CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword;
}

Since Baum\Node is extending Eloquent Model, just like the mentioned User class does, I have changed my User class to this:

use Baum\Node;
use Illuminate\Notifications\Notifiable;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Node  implements
    AuthenticatableContract,
    AuthorizableContract,
    CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword, Notifiable;

[...]

Don't forget to update the database with parent_id, lft,rgt and depth.

parusel avatar Oct 28 '16 11:10 parusel