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

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

Closed
seche opened this issue Jun 30, 2021 · 3 comments
Closed

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

seche opened this issue Jun 30, 2021 · 3 comments

Comments

@seche
Copy link

seche commented Jun 30, 2021

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?

@bolechen
Copy link
Owner

bolechen commented Apr 7, 2022

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

@seche
Copy link
Author

seche commented May 30, 2022

@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
Copy link
Author

seche commented Mar 24, 2023

@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

@bolechen bolechen pinned this issue May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants