WildsideUK / Laravel-Userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created_by` and `updated_by` columns on your model, populated by the currently authenticated user in your application.
https://wildside.uk
MIT License
570 stars 64 forks source link

SoftDeletes not work if SoftDeletes is used in a parent class #8

Closed superbull closed 7 years ago

superbull commented 7 years ago

For example:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;
use Watson\Validating\ValidatingModel;

class Base extends ValidatingModel
{
    use SoftDeletes;
}
<?php

namespace App\Models;

use Wildside\Userstamps\Userstamps;
use App\Models\User;

class Team extends Base
{
    use Userstamps;
}

If you delete Team, the deleted_by field will not be filled with current user.

This is because the return value of the PHP function class_uses does not include any traits used by a parent class. See: http://php.net/manual/en/function.class-uses.php

mattmcdonald-uk commented 7 years ago

Thanks for opening this issue and the PR (sorry it's taken me so long to get around to looking at it!)

Agreed this is needed, but there's an existing helper method 'class_uses_recursive' which we can use to achieve this.

Fixing with 2d8e5ca872249c0a256c262f45f03e307501fdbf