Custom view page and display for relation model

Hello Guys !! any one give me example or sample of custom view page ? i would like to display some data from another model
30 Replies
toeknee
toeknee2y ago
Can you give details of what you are trying to achieve
ironheartkh
ironheartkhOP2y ago
after generated view record i got display same data as input form but i want to custom it and view with additional data from model search in old topic but still confusing because am newbie with filament
toeknee
toeknee2y ago
So you have a resource right? And when you use view you see a form? And you want to customise the form with data from relationships?
ironheartkh
ironheartkhOP2y ago
yes like example i got filed to input user_id (f_id for one to one relationship) and in view i may only get user_id but also want to access to username via that user_id
toeknee
toeknee2y ago
Do you want to allow the user_id to be editable? If you have a relationship on the model you just call the relationship and it's fields with a dot syntax. So a user() relationship on the resource model you can do: TextInput::make('user.username')->label('User Name')->disabled(true);
ironheartkh
ironheartkhOP2y ago
no i don't allow user_id should fill default with logged in user ID i only want to display on view page only for username
toeknee
toeknee2y ago
So remove it from the form completely as that is insecure, set it via: https://filamentphp.com/docs/2.x/admin/resources/creating-records#customizing-data-before-saving
Filament
Creating records - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
Dennis Koch
Dennis Koch2y ago
You can overwrite the form() on the EditPage Or use visibleOn() for the fields you want only on the view page.
ironheartkh
ironheartkhOP2y ago
can you give me sample code ?
ironheartkh
ironheartkhOP2y ago
thank you for that is there anything i can use another from Textinput ? because it only for display how can i enable debug on filament ? my app debug is true but no debug mode
toeknee
toeknee2y ago
App Debug will be correct, do you mean there is no debug toolbar?
ironheartkh
ironheartkhOP2y ago
i want to show my model to see data but it not showing like normal laravel
ironheartkh
ironheartkhOP2y ago
we need to use third party ?
toeknee
toeknee2y ago
How are you trying to do that? You just run a dd() on the place you want it to do it?
ironheartkh
ironheartkhOP2y ago
how can i called it to run dd ?
toeknee
toeknee2y ago
In mount or render functions if you really wish, but the model will have all the fields your model has native access too.
ironheartkh
ironheartkhOP2y ago
something like this ?
ironheartkh
ironheartkhOP2y ago
i don't get dd to work
Dennis Koch
Dennis Koch2y ago
There is not mount() in Resources
toeknee
toeknee2y ago
Mount won't work on the resource, you would need to do it on the edit or create page. But I don't understand why you are just DDing there
Dennis Koch
Dennis Koch2y ago
You can't just drop a method call inside a class definition.
ironheartkh
ironheartkhOP2y ago
let me explain you guys step by step maybe my english is not quite good enough to make them understand 1.i generate resource with --view 2.i would like to make custom page for my view some data want to display from relation not from form that use in ModelResource 3.access to view by primary id of model but what if in my model i use uuid instead of id integer auto increase ? can i still able to access my view page using my uuid ? something like /mode/view/uuid
Dennis Koch
Dennis Koch2y ago
Did you set the primary key on your model?
ironheartkh
ironheartkhOP2y ago
yes i do but when i'm trying to access it not working when i click view it got something like this /model/view/0 i got 0 like it's not able to find my uuid but if i copy uuid and paste it working
toeknee
toeknee2y ago
So your primary is uuid not id ? Did you set the primary key in the model?
ironheartkh
ironheartkhOP2y ago
yes i do when i check database, do you need any screenshot to make sure for my question ?
ironheartkh
ironheartkhOP2y ago
i got it now, thank you guys
Dennis Koch
Dennis Koch2y ago
Maybe wanna share your solution for people finding this through search?
ironheartkh
ironheartkhOP2y ago
Sure 1, use HasUuids in your Model 2,in migration $table->uuid('id')->primary()->unique()->first();
Want results from more Discord servers?
Add your server