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

Doesn't work with spatie / laravel-permission #99

Closed
Belgiets opened this issue Aug 20, 2020 · 6 comments
Closed

Doesn't work with spatie / laravel-permission #99

Belgiets opened this issue Aug 20, 2020 · 6 comments

Comments

@Belgiets
Copy link

I am using default setup of spatie / laravel-permission package and lada-cache packages. Everything works well except user<->roles relation.

class User extends Authenticatable
{
use HasRoles;
use LadaCacheTrait;

// ...

}

If i try to make request with 'roles' relation i'm getting an exception.

\App\User::whereHas('roles')->get();

TypeError
Argument 1 passed to Spiritix\LadaCache\Reflector::getTablesFromWhere() must be an instance of Spiritix\LadaCache\Database\QueryBuilder, instance of Illuminate\Database\Query\Builder given, called in /home/belgiets/projects/laravel7/vendor/spiritix/lada-cache/src/Spiritix/LadaCache/Reflector.php on line 145

Reproduced on clear installation of:

  • "laravel/framework": "^7.24"
  • "spatie/laravel-permission": "^3.16"
  • "spiritix/lada-cache": "^5.0"
@denzndhauz
Copy link

I'm having the same issue. I hope they can answer this.

packages versions:

"laravel/framework": "^7.0",
"spatie/laravel-permission": "^3.13",
"spiritix/lada-cache": "^5.0"

@spiritix
Copy link
Owner

spiritix commented Oct 1, 2020

Hi guys. As of now, there is no official support for this package. Will add it to the wish list, contributions are welcome.

@Dietermartens
Copy link

We have it working with these versions:

"laravel/framework": "^7.0",
"spatie/laravel-permission": "3.17.0",
"spiritix/lada-cache": "v5.1",

@spiritix
Copy link
Owner

Can you re-test this please with the latest release (v5.1.2) please? Could be that it fixes this issue as well.

@zgetro
Copy link

zgetro commented Jan 20, 2022

Main resone behind his error is only that Models/Role.php and Models/Permission.php both don't have use \Spiritix\LadaCache\Database\LadaCacheTrait; some how config/lada-cache.php exclude-tables feature is not working for spaties tables(did not checked how they ingnored).

if any one found same issue with other packages ( like spatie/permission ) they must need to check models has LadaCacheTrait trait.

in my case i have extended Permission, Role Models and add use Spiritix\LadaCache\Database\LadaCacheTrait;

<?php

namespace App;

use Spatie\Permission\Models\Permission as SpatiePermission;

class Permission extends SpatiePermission
{
    use \Spiritix\LadaCache\Database\LadaCacheTrait;
}
<?php

namespace App;

use Spatie\Permission\Models\Role as SpatieRole;

class Role extends SpatieRole
{
    use \Spiritix\LadaCache\Database\LadaCacheTrait;
}

to pass my custom models to spatie/permission package i have change configration config/permission.php

<?php

return [

    'models' => [

        'permission' => App\Permission::class,

        'role' => App\Role::class,

    ],

and It works Thanks @spiritix for wonderfull free code. hop that help to solve problem in upcomming version.

@spiritix
Copy link
Owner

@zgetro Thanks for providing a solution to this problem. I will reference it in the README, since similar workarounds can be used for other packages as well. Unfortunately, I don't think that issues with third-party libraries are generically solvable within Lada Cache. I'd have to look at every package in detail and develop a custom solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants