Answer the question
In order to leave comments, you need to log in
The cybercog/laravel-ban package, when unblocked, returns null and does not unblock the user, why?
Another question about the cybercog/laravel-ban package .
There is a user unlock code (after blocking):
/**
* Разблокировка пользователя
* @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('Пользователь ' . $user->login . ' успешно разблокирован!')
->success();
return redirect()->intended(route('admin.users'));
}else{
flash('Ошибка при разблокировке пользователя!')->warning();
return redirect()->back();
}
}else{
flash('Невероятно, но тут ошибка!)')->info();
return redirect()->intended(route('admin.users'));
}
}
@if($user->isBanned())
<tr class="table-danger">
@else
<tr>
@endif
<th scope="row">{{ $user->id }}</th>
<td>{{ $user->login }}</td>
<td>{{ $user->mail }}</td>
<td>{{ ($user->status) ? 'Активирован' : 'Не активирован' }}</td>
<td>{{ $user->created_at }}</td>
<td>
@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
</td>
</tr>
<?php
namespace App;
use Cog\Contracts\Ban\Bannable as BannableContract;
use Cog\Laravel\Ban\Traits\Bannable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable implements BannableContract{
use Notifiable, HasRoles, Bannable;
protected $fillable = ['login', 'mail', 'password', 'banned_at'];
protected $hidden = ['password', 'remember_token'];
protected $dates = ['deleted_at', 'banned_at'];
/**
* Поле E-Mail адреса для уведомлений
* @return mixed
*/
public function routeNotificationForMail(){
return $this->mail;
}
/**
* Шифруем пароль по умолчанию функцией bcrypt.
* @param $password
*/
public function setPasswordAttribute($password){
$this->attributes['password'] = bcrypt($password);
}
/**
* Не даём заблокированным пользователям заходить в свой аккаунт
* @return bool
*/
public function shouldApplyBannedAtScope(){
return true;
}
}
Answer the question
In order to leave comments, you need to log in
there is no return in unban()
check $user->isBanned();
and learn how to work with documentation and source codes
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question