nova-activitylog
nova-activitylog copied to clipboard
Field MorphTo::make('Causer', 'causer') not displaying anything.
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?
What version of nova are you using? Can you provide some more detailed information?
@bolechen
In the fields for the ActivityLog resource MorphTo::make('Causer', 'causer')
shows a dash like I highlighted in the yellow part below.
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.
@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