nova-activitylog icon indicating copy to clipboard operation
nova-activitylog copied to clipboard

Field MorphTo::make('Causer', 'causer') not displaying anything.

Open seche opened this issue 3 years ago • 2 comments

In fields for the ActivityLog resource: MorphTo::make('Causer', 'causer'), doesn't return a displayable value. It simply shows a dash for all activities. Meanwhile the database has the correct causer type and causer id.

Did you need to add anything to the user model to accept the relationship? or to the Nova User resource?

seche avatar Jun 30 '21 17:06 seche

What version of nova are you using? Can you provide some more detailed information?

bolechen avatar Apr 07 '22 03:04 bolechen

@bolechen

In the fields for the ActivityLog resource MorphTo::make('Causer', 'causer') shows a dash like I highlighted in the yellow part below.

image

SO I had to extend the class and using a text field I generated the link to the user object. Not ideal but works as you can see above the next column to the yellow one.

public function fields(Request $request)
    {
        return [
...
            MorphTo::make('Causer', 'causer'),
            Text::make('Causer', 'causer_id')->displayUsing(function ($user_id) {
                return '<a href="/nova/resources/users/'.$user_id.'" class="no-underline dim text-primary font-bold">'. strtoupper(\App\Models\User::find($user_id)->username) . '</a>';
            })->asHtml(),
....

We're still using Nova 3.

seche avatar May 30 '22 19:05 seche

@bolechen Found the answer. Might want to add to the documentation that the Causer requires that the Causer Nova resource has the title defined for it to display on the index and select inputs on the form view. In most cases that would be the User Nova resource.

/**
 * Get the value that should be displayed to represent the resource.
 *
 * @return string
 */
public function title()
{
    return $this->name;
}

Or public static $title = 'name';

Ref: https://nova.laravel.com/docs/1.0/resources/relationships.html#title-attributes

seche avatar Mar 24 '23 15:03 seche