Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to display "comment" on the resource page #10

Open
saleh-old opened this issue Mar 29, 2020 · 2 comments
Open

How to display "comment" on the resource page #10

saleh-old opened this issue Mar 29, 2020 · 2 comments
Labels
question Further information is requested

Comments

@saleh-old
Copy link

How can I display the "comment" (reason user was banned) in the User resource detail page?

Thank you

@antonkomarev antonkomarev added the question Further information is requested label Mar 29, 2020
@antonkomarev
Copy link
Member

Sorry, I don't know, I haven't started to use Nova in any of my projects. Maybe somebody else know how to do it.

@kilrizzy
Copy link

I just defined the reason (along with other ban fields) as accessors:

public function getBannedAttribute()
{
        return $this->isBanned();
}

public function getBannedUntilAttribute()
{
        $ban = $this->bans()->first();
        if($ban){
            return $ban->expired_at;
        }
        return null;
}

public function getBannedReasonAttribute()
{
        $ban = $this->bans()->first();
        if($ban){
            return $ban->comment;
        }
        return null;
}

So then you can just drop them into your Nova field like:

Boolean::make('Banned')
        ->sortable()
         ->hideWhenCreating()
        ->hideWhenUpdating(),

Date::make('Banned Until')
        ->onlyOnDetail(),

Text::make('Banned Reason')
        ->onlyOnDetail(),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants