chuckbe /
chuckcms
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Chuckbe\Chuckcms\Models; |
||
| 4 | |||
| 5 | use Illuminate\Foundation\Auth\User as Authenticatable; |
||
| 6 | use Illuminate\Notifications\Notifiable; |
||
| 7 | use Spatie\Permission\Traits\HasRoles; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @property string $name |
||
| 11 | * @property string $email |
||
| 12 | * @property string $token |
||
| 13 | */ |
||
| 14 | class User extends Authenticatable |
||
| 15 | { |
||
| 16 | use HasRoles; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 17 | use Notifiable; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * The attributes that are mass assignable. |
||
| 21 | * |
||
| 22 | * @var array |
||
| 23 | */ |
||
| 24 | protected $fillable = [ |
||
| 25 | 'name', 'email', 'password', 'active', 'token', |
||
| 26 | ]; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The attributes that should be hidden for arrays. |
||
| 30 | * |
||
| 31 | * @var array |
||
| 32 | */ |
||
| 33 | protected $hidden = [ |
||
| 34 | 'password', 'remember_token', |
||
| 35 | ]; |
||
| 36 | |||
| 37 | protected $guard_name = 'web'; |
||
| 38 | |||
| 39 | public function deleteById($id) |
||
| 40 | { |
||
| 41 | $user = $this->where('id', $id)->first(); |
||
| 42 | if ($user) { |
||
| 43 | $roles = $user->getRoleNames(); |
||
| 44 | $permissions = $user->getDirectPermissions(); |
||
| 45 | |||
| 46 | foreach ($roles as $role) { |
||
| 47 | $user->removeRole($role); |
||
| 48 | } |
||
| 49 | foreach ($permissions as $permission) { |
||
| 50 | $user->removePermissionTo($permission); |
||
| 51 | } |
||
| 52 | |||
| 53 | if ($user->delete()) { |
||
| 54 | return 'success'; |
||
| 55 | } else { |
||
| 56 | return 'error'; |
||
| 57 | } |
||
| 58 | } else { |
||
| 59 | return 'false'; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 |