Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in AuditableObserver (v5.0) #354

Closed
Albvadi opened this issue Nov 29, 2017 · 11 comments
Closed

Error in AuditableObserver (v5.0) #354

Albvadi opened this issue Nov 29, 2017 · 11 comments
Assignees
Labels
help wanted Assistance or contributions needed

Comments

@Albvadi
Copy link
Contributor

Albvadi commented Nov 29, 2017

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 5.5.22
Package version 5.0.0
PHP version 7.0.9

Actual Behaviour

Error trying to save a new instance of a audit model.

Steps to Reproduce

App\Company.php (Model)

use OwenIt\Auditing\Contracts\Auditable;
class Company extends Model implements Auditable
{
    use SoftDeletes;
    use \OwenIt\Auditing\Auditable;

    ...
}

Route

Route::get('/create_company', function () {
    dd((factory(App\Company::class)->create())->toArray());
});

Error:
image

@Albvadi Albvadi changed the title Error in AuditableObserver Error in AuditableObserver (v5.0) Nov 29, 2017
@quetzyg
Copy link
Contributor

quetzyg commented Nov 29, 2017

You sure you're on PHP 7.0.9? The only time I had issues like that was with PHP 5.5.x/5.6.x, where I had to use an alias. PHP 7.0.9 shoud be OK with using the same class name, as long as at least one is using the FQCN.

Anyways, try:

use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

class Company extends Model implements AuditableContract
{
    use SoftDeletes;
    use \OwenIt\Auditing\Auditable;

    ...
}

@quetzyg quetzyg closed this as completed Nov 29, 2017
@quetzyg
Copy link
Contributor

quetzyg commented Nov 29, 2017

The issue was fixed in PHP 7.0.7, btw.

@Albvadi
Copy link
Contributor Author

Albvadi commented Nov 30, 2017

Sure, my PHP version it´s 7.0.9. Load in a phpinfo() page inside laravel.

I followed your suggestion, but the problem persist.
Besides, I created and empty laravel installation, only just in case I had forgotten something in the upgrade from 4.1.4 and same problem.

In the new installation, with all default config:
App\User.php

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use OwenIt\Auditing\Contracts\UserResolver;

class User extends Authenticatable implements UserResolver
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * {@inheritdoc}
     */
    public static function resolveId()
    {
        return Auth::check() ? Auth::user()->getAuthIdentifier() : null;
    }
}

App\Company.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;

class Company extends Model implements AuditableContract
{
    use \OwenIt\Auditing\Auditable;
}

routes\web.php

Route::get('/company', function () {
    $company = new Company;
    $company->name = "TEST COMPANY";
    $company->save();
});

Same error in a source file from the package (\vendor\owen-it\laravel-auditing\src\AuditableObserver.php), not in my source code:
image

@quetzyg
Copy link
Contributor

quetzyg commented Nov 30, 2017

I followed your suggestion, but the problem persist.

No you didn't, you're not using an alias, like I have in the example above.

@Albvadi
Copy link
Contributor Author

Albvadi commented Nov 30, 2017

Was a copy/paste problem... sorry.
But, tried with your suggestion... problem persist.

image
image

@Albvadi
Copy link
Contributor Author

Albvadi commented Nov 30, 2017

Besides, downgrade from 5.0.1 to 4.1.4, works perfect without touching my model setup

@quetzyg
Copy link
Contributor

quetzyg commented Nov 30, 2017

Any 4.1.x version has the alias set to prevent such issue, but like I said, this is a PHP 5.5.x/5.6.x and 7.0.0 to 7.0.7 problem.

These are the PHP 5.5.21 and 5.6.5 builds failing on Travis CI, exactly because of that. Once I added aliases, the tests passed.

Tests don't lie.
#shakira

The issue you're having should not happen in the PHP version you say you have. So you either have multiple PHP versions and you think you're using one, instead of another, or the issue wasn't properly fixed in PHP 7.0.7 and you need a higher version.

Try upgrading to a more recent PHP version and see if the issue disappears.

Version 7.0.x won't be actively supported for much longer, anyway.

@Albvadi
Copy link
Contributor Author

Albvadi commented Nov 30, 2017

Upgraded PHP to 7.0.13 solve the issue without using alias.

I'm sorry I bothered you so much.
Maybe you should update the readme.md to avoid people like me.

Thanks for all your support!

@quetzyg
Copy link
Contributor

quetzyg commented Nov 30, 2017

Not a problem, I'll update the composer.json requirements and bump the PHP version to avoid similar issues.

@quetzyg
Copy link
Contributor

quetzyg commented Nov 30, 2017

I just checked the changelog for 7.0.13 and it does fix the issue.

@Albvadi
Copy link
Contributor Author

Albvadi commented Nov 30, 2017

I thought I was going crazy!!
Thanks for your research!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Assistance or contributions needed
Projects
None yet
Development

No branches or pull requests

2 participants