romanbican / roles

Powerful package for handling roles and permissions in Laravel 5
MIT License
1.16k stars 297 forks source link

laravel 5.2 support #144

Open rjcrystal opened 8 years ago

rjcrystal commented 8 years ago

does this package support laravel 5.2? laravel 5.2 has new multi-auth and multi-model auth

wotta commented 8 years ago

I tried installing the package but could not get it to work since it returns with an error.

msieprawski commented 8 years ago

+1

frankiecmk commented 8 years ago

+1

JoeriAben commented 8 years ago

Any ETA of the support for laravel 5.2?

Cardy commented 8 years ago

+1

nagarajan010 commented 8 years ago

+1

defji commented 8 years ago

+1

devillom commented 8 years ago

+1

yuansir commented 8 years ago

+1

florianbinderme commented 8 years ago

+1

ghost commented 8 years ago

+

Skintillion commented 8 years ago

What's the error?

ghost commented 8 years ago

I get the error FatalErrorException in User.php line 10: Class 'App\Model' not found

All I have done is install laravel and add bican/roles package. no other major changes to namespaces or models. Any ideas why I would be getting this error? user.php starts like this... `<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable; use Bican\Roles\Traits\HasRoleAndPermission; use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract { use Authenticatable, CanResetPassword, HasRoleAndPermission;`

SteveFound commented 8 years ago

Add a use Illuminate\Database\Eloquent\Model to your 'use' list

ghost commented 8 years ago

thanks SteveFound...so simple but totally missed it. added some more use statements to fix subsequent errors only to find that I get the following error looking like this now but still getting an error `<?php

namespace App;

use App\Task; use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Auth\User as Authenticatable; use Bican\Roles\Traits\HasRoleAndPermission; use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract { use Authenticatable, CanResetPassword, HasRoleAndPermission;`

Error I'm getting now is: FatalErrorException in User.php line 15: App\User cannot use Illuminate\Foundation\Auth\User - it is not a trait

ghost commented 8 years ago

managed to register error free using the following...now to test the roles/permissions with 5.2. Thanks for your help SteveFound.

<?php

namespace App;

use App\Task; use Illuminate\Database\Eloquent\Model; use Illuminate\Auth\Authenticatable; use Illuminate\Auth\Passwords\CanResetPassword; use Bican\Roles\Traits\HasRoleAndPermission; use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract { use Authenticatable, CanResetPassword, HasRoleAndPermission;

ghost commented 8 years ago

Looks like it is working fine in 5.2, so far so good.

Skintillion commented 8 years ago

Excellent. On 2016-02-09 6:09 PM, "Jobielou" notifications@github.com wrote:

Looks like it is working fine in 5.2, so far so good.

— Reply to this email directly or view it on GitHub https://github.com/romanbican/roles/issues/144#issuecomment-182169073.

akrz commented 8 years ago

if someone used the artisan make:auth command, you can use this package by writing your User class as:

use Illuminate\Foundation\Auth\User as Authenticatable;
use Bican\Roles\Traits\HasRoleAndPermission;
use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract;

class User extends Authenticatable implements HasRoleAndPermissionContract
{
    use HasRoleAndPermission;
...
pedritoelcabra commented 8 years ago

@akrz

When using your solution:

$user->is($role)

returns false even when the role is attached correctly

Solution from @jobielou works for me

I did use make:auth

roberttolton commented 8 years ago

I can't get this working, here's my User.php:

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

use Illuminate\Auth\Passwords\CanResetPassword;
use Bican\Roles\Traits\HasRoleAndPermission;
use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Authenticatable implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract {

    use Authenticatable, CanResetPassword, HasRoleAndPermission;

    protected $fillable = [
        "name", "email", "password",
    ];

    protected $hidden = [
        "password", "remember_token",
    ];

    public function presentations () {

        return $this->hasMany( "App/Presentation" );

    }

}

Depending on how I alter the file, I get a range of errors:

vagrant@precise64:/vagrant$ php artisan db:seed --class=PermissionsSeeder

  [BadMethodCallException]                                                  
  Call to undefined method Illuminate\Database\Query\Builder::attachRole()  

vagrant@precise64:/vagrant$ php artisan db:seed --class=PermissionsSeeder
PHP Fatal error:  App\User cannot use Illuminate\Foundation\Auth\User - it is not a trait in /vagrant/app/User.php on line 15

  [Symfony\Component\Debug\Exception\FatalErrorException]                  
  App\User cannot use Illuminate\Foundation\Auth\User - it is not a trait  

Any ideas?

UPDATE

I'm now using just this:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Bican\Roles\Traits\HasRoleAndPermission;
use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract {

    use Authenticatable, CanResetPassword, HasRoleAndPermission;

    protected $fillable = [
        "name", "email", "password",
    ];

    protected $hidden = [
        "password", "remember_token",
    ];

    public function presentations () {

        return $this->hasMany( "App/Presentation" );

    }

}

Getting the error:

[BadMethodCallException]                                                  
  Call to undefined method Illuminate\Database\Query\Builder::attachRole()
roberttolton commented 8 years ago

Herp, I manage to miss the fact that my users array wasn't returning anything because my table got accidentally emptied by another seed.. it seems to be working now.

fzhan commented 8 years ago

By updating the function "can" to "canDo", fix the issue of Trait method collision

yong0011 commented 8 years ago

Thanks @jobielou