Comments (4)
{{ $user->bans->last()->expired_at }}
that worked
from laravel-ban.
Could you show your User model and error message?
from laravel-ban.
no error message
public function ban($id)
{
$user = User::where('id', $id)->first();
$user->ban([
'expired_at' => '+1 month',
]);
}
user model
?php
namespace App\Models;
use Ansezz\Gamify\Traits\Gamify;
use Laravel\Sanctum\HasApiTokens;
use Cog\Laravel\Ban\Traits\Bannable;
use Overtrue\LaravelLike\Traits\Liker;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Overtrue\LaravelFavorite\Traits\Favoriter;
use Overtrue\LaravelSubscribe\Traits\Subscriber;
use Cog\Contracts\Ban\Bannable as BannableContract;
use Overtrue\LaravelFollow\Followable as Followable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable implements BannableContract
{
use HasApiTokens, HasFactory, Notifiable;
use Followable, Bannable, Liker;
use Subscriber, Gamify, Favoriter;
/**
* The attributes that are mass assignable.
*
* @var string[]
*/
protected $guarded = [];
protected $fillable = [
'name',
'email',
'username',
'password',
'phone_number',
'isVerified',
'creator_name',
'creator_bio',
'avatar',
'gender',
];
public function post()
{
return $this->hasMany(Post::class);
}
public function withdraw()
{
return $this->hasOne(Withdraw::class);
}
public function tickets()
{
return $this->hasMany(Ticket::class);
}
// public function getAvatarAttribute()
// {
// if ($this->attributes['avatar']){
// return $this->attributes['avatar'];
// }
// return $this->attributes['gender'] === 'm' ? 'img/male.png' : 'img/female.png';
// }
public function getAvatarAttribute()
{
if ($this->attributes['avatar']) {
return $this->attributes['avatar'];
}
return [
'm' => asset('img/male.png'),
'f' => asset('img/female.png'),
// ...
][$this->attributes['gender']] ?? asset('img/mys.png');
}
public function movie()
{
return $this->hasMany(Movie::class);
}
/**
* The attributes that should be hidden for serialization.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
from laravel-ban.
Try this one
{{ $user->bans->last()->expired_at }}
But it is not great to make DB calls in view files, it's better to make all queries in controllers or descendant classes.
from laravel-ban.
Related Issues (20)
- Support for user UUIDs HOT 8
- How do I get information about a blocked user ? HOT 2
- Laravel 7 compatibility HOT 3
- how can I ban only once? HOT 2
- $user->isNotBanned not working in a blade file HOT 1
- Send notification on unban HOT 1
- Add support for more states HOT 3
- Laravel 8 unsupport and bug HOT 4
- PHP 8.0 support HOT 1
- Inertia compatibility HOT 4
- Middlewares
- Dosen´t refresh the collection when I ban a user HOT 4
- Laravel 9 HOT 1
- allow us to configure the table on different connection / database please HOT 4
- Laravel API Middleware useage HOT 1
- Should add Qualified Banned At column name in scopes like SoftDeletes Trait
- Remove laravel/legacy-factory dev dependency
- bannable trait HOT 2
- something weird when banning models multiple times. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-ban.