Giter Club home page Giter Club logo

Comments (4)

Elusoji avatar Elusoji commented on July 30, 2024 1

{{ $user->bans->last()->expired_at }}

that worked

from laravel-ban.

antonkomarev avatar antonkomarev commented on July 30, 2024

Could you show your User model and error message?

from laravel-ban.

Elusoji avatar Elusoji commented on July 30, 2024

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.

antonkomarev avatar antonkomarev commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.