Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SharipovIskandar's avatar

Help Needed with Displaying Specific Column from StudentResource in Moonshine

Hello everyone,

I am currently working with Moonshine, a Laravel-based admin panel package, and I’m facing an issue with displaying a specific column from the data coming through StudentResource.

About my current task: I’m building an admin panel where users can manage student records. Each student record has a relation to the User model (the person who is responsible for that student). I am using Moonshine to create an admin interface, and I want to show a list of users that can be assigned to students. However, I need to display a specific column (e.g., just the user's name) from the StudentResource instead of showing the whole resource.

Here’s what I’m trying to do:

I want to display the name of the user (e.g., "John Doe") in the dropdown field where the admin selects the user for a student, but Moonshine is showing all the data from the StudentResource, which I don't need.

For example, the dropdown should show something like:

John Doe
Jane Smith

But it’s currently showing something like:

User id: 1
User id: 2

The problem: I want to display only the name field in the dropdown, but I’m not sure how to extract just the specific column (e.g., name) from the StudentResource or the associated User model.

Here is the code I am using:

BelongsTo::make('User id', 'user', resource: StudentResource::class)->searchable(),

This code links the User model to the StudentResource, but it’s not displaying just the name field from the User model.

My setup:

Laravel version: 11.31
Moonshine version: 3.2
StudentResource is a resource for the student model, and I'm trying to link it to the User model.

Could anyone point me in the right direction? How can I specify which column to display from the User model or StudentResource? I’m looking to show just the user’s name in the dropdown field.

Thank you in advance!

0 likes
3 replies
Snapey's avatar
Snapey
Best Answer
Level 122

no, its not enough.

Don't assume we know what moonshine is

Those lines of code are meaningless out of context

Show what you tried and what you got.

SharipovIskandar's avatar

@Snapey I am sure the answer to this issue will be found, just like all the others. This was my first question on the forum, and I am very grateful to you. Once I find the answer, I will definitely leave it as a reply. Thanks to everyone who is helping with others' issues!

SharipovIskandar's avatar

I wanted to share the solution to the issue I raised earlier about displaying a specific column (user_id or email) from StudentResource in Moonshine.

Problem Recap: I was trying to use BelongsTo to display specific data (e.g., email) from the User model in a dropdown field. Initially, I was seeing the entire User model data instead of just the column I needed.

Solution: The issue was resolved by using the formatted option in the BelongsTo field. Here’s the updated code that worked perfectly for me:

protected string $column = 'email';

BelongsTo::make( 'Email', 'user', formatted: fn($item) => $item->email, resource: StudentResource::class )->searchable(),

What this does:

formatted option: Allows me to specify what part of the related data (in this case, email) should be displayed in the dropdown.
This ensures only the email address appears in the dropdown while keeping the link to the full user details page functional.

Outcome: Now, the dropdown shows only the email address for each user, and when I click on an item, it navigates to the detailed user page as expected.

I hope this solution helps others facing a similar issue.

Please or to participate in this conversation.