Package cybercog/laravel-ban, when you unlock, it gives null and unlocks user, why?

Back to the issue of package cybercog/laravel-ban.

Is the unlock code of the user (after blocking):
/**
 * Unlock user
 * @param int $id
 * @return \Illuminate\Http\RedirectResponse
*/
 public function unbanUser(int $id){
 $user = User::onlyBanned()->find($id);

if($user){
 $unbanUser = $user->unban();

if($unbanUser){
 flash('the User' . $user->login . ' is successfully unlocked!')
->success();

 return redirect()->intended(route('admin.users'));
}else{
 flash('Error when unlocking a user!')->warning();

 return redirect()->back();
}
}else{
 flash('Unbelievable, but then an error!)')->info();

 return redirect()->intended(route('admin.users'));
}
 }


And view buttons to unlock:
@if($user->isBanned())

@else

@endif

 {{ $user->id }}
 {{ $user->login }}
 {{ $user->mail }}
 {{ ($user->status) ? 'Enabled' : 'Not enabled' }}
 {{ $user->created_at }}

@can('admin.users.banned')
@if($user->isNotBanned())
 <a href="{{ route('admin.users.banned', $user->id) }}">
 <i class="fa fa-ban text-danger" style="font-size: 2em;"></i>
</a>
@endif
@endcan

@can('admin.users.endBanned')
@if($user->isBanned())
 <a href="{{ route('admin.users.endbanned', $user->id) }}">
 <i class="fa fa-check-circle text-success" style="font-size: 2em;"></i>
</a>
@endif
@endcan



When you press unlock does not pass, because it gives null in the method $user->unban(); Himself $user exists and data is there.

In any case, the User model:
<?php
namespace App;

use Cog\Contracts\Ban\Bannable as BannableContract;
use Cog\Laravel\Ban\Traits\Bannable;
use Illuminate\Notifications\is a notifiable;
use Illuminate\Foundation\Auth\Authenticatable as User;
use Spatie\Permission\Traits\HasRoles;

class User extends implements Authenticatable BannableContract{
 the use is a notifiable, HasRoles, Bannable;

 protected $fillable = ['login', 'mail', 'password', 'banned_at'];
 protected $hidden = ['password', 'remember_token'];
 protected $dates = ['deleted_at', 'banned_at'];

/**
 * The field E-Mail address for notifications
 * @return mixed
*/
 public function routeNotificationForMail(){
 return $this--->mail;
}

/**
 * Encrypt password default function bcrypt.
 * @param $password
*/
 public function setPasswordAttribute($password){
 $this->attributes['password'] = bcrypt($password);
}

/**
 * Do not give blocked users to log in to your account
 * @return bool
*/
 public function shouldApplyBannedAtScope(){
 return true;
}
}


Thanks in advance!

UPD: if in delete deleted_at (or rather null to do), it gives error: "Trying to get property 'bans' of non-object", and in database there appears a new date (Carbon::now).
June 5th 19 at 22:03
1 answer
June 5th 19 at 22:05
Solution
in unban() no return
check $user->isBanned();
and learn how to work with documentation and source code
$user->isBanned() yields true, i.e. the user is blocked. - Jamaal_Bode commented on June 5th 19 at 22:08
The code works, but the user is still locked. Another check isBanned proof. - Jamaal_Bode commented on June 5th 19 at 22:11
As I understood from source - unban() unblock data array, and not a single user, which I choose. It's very strange, because in the docks is not specified. - Jamaal_Bode commented on June 5th 19 at 22:14
you not correctly understood. .... in this disadvantages of using bags without an understanding of how something works. after all, he suggested I soft_deletes you to use.
1. posmotre what is checked in isBanned()
2. Check that the trigger events - florencio.Zemlak60 commented on June 5th 19 at 22:17
after all, he suggested I soft_deletes you to use

I do not remember
posmotre what is checked in isBanned()

he compares banned_at data in the users table.
Check that the trigger events

do not tell me how to do it? - Jamaal_Bode commented on June 5th 19 at 22:20
well put die('bla-bla-bla'), at least.
no, really, not like you soft_deletes offered.
bans are stored in a separate table. Unban() deletes the associated user record. Ban() - adds.
In the users table there is a field banned_at - the value of which varies with ban() / unban() -- change is invoked in BanObserver.php.
If the bath user has changed, and if unban() no, then all the magic happens. Or you have something incorrectly hooked up, or even 10050 options. - florencio.Zemlak60 commented on June 5th 19 at 22:23
you can still manually - florencio.Zemlak60 commented on June 5th 19 at 22:26
die in unban() or anything, but as null will not. Because neither of which this method does not issue. Although I tried to make a return in this method.

bans are stored in a separate table. Unban() deletes the associated user record. Ban() - adds.
In the users table there is a field banned_at - the value of which varies with ban() / unban() -- change is invoked in BanObserver.php.


If the bath user has changed, and if unban() no, then all the magic happens.


Yes. Very cool that the first unban the bans table changes field delete_at, though, and the lock still does not stop. And in the users table, the field banned_at only changes when Bane (ban()), and if unban or what not to change. - Jamaal_Bode commented on June 5th 19 at 22:29
all these "fun" was visible in the source code. And this is normal behavior. The only thing wrong is not activated in the observer when unban. In this way, and dig. - florencio.Zemlak60 commented on June 5th 19 at 22:32
The only thing wrong is not activated in the observer when unban. In this way, and dig.

Unfortunately, this is out of my hands(

And are there any similar packages? - Jamaal_Bode commented on June 5th 19 at 22:35
And again advise you to refuse the package and write your own from scratch. Try to build a lock-based user soft_deleted. Understand how it works, how scopes work. Then independently add the banned_at and use it instead of deleted_at. If necessary, add a field/table bans.
You don't have a reasonable understanding of the basics of PHP. Without this and Laravel, and even the individual bags will seem magic with which it is not clear what to do.
You study or earn money? Learn - start to write code themselves. And for ready - made solutions made to pay. - florencio.Zemlak60 commented on June 5th 19 at 22:38
You study or earn money?

Learn. Make the project for yourself.
Learn - start to write code themselves.

A lot and so I try to write. But due to some gaps in my knowledge of PHP etc. - take the package.

Will have to write. To do that will I do, but I feel the structure would do not correctly. - Jamaal_Bode commented on June 5th 19 at 22:41
I can't "feel" wrong, correct it. It all started with this. Good luck. - florencio.Zemlak60 commented on June 5th 19 at 22:44

Find more questions by tags Laravel