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
Can you give details of what you are trying to achieve
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
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?
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
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);
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
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.
You can overwrite the
form()
on the EditPage
Or use visibleOn()
for the fields you want only on the view page.can you give me sample code ?
Filament
Getting started - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
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
App Debug will be correct, do you mean there is no debug toolbar?
i want to show my model to see data but it not showing like normal laravel
we need to use third party ?
How are you trying to do that? You just run a dd() on the place you want it to do it?
how can i called it to run dd ?
In mount or render functions if you really wish, but the model will have all the fields your model has native access too.
something like this ?
i don't get dd to work
There is not
mount()
in ResourcesMount 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
You can't just drop a method call inside a class definition.
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
Did you set the primary key on your model?
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
So your primary is uuid not id ? Did you set the primary key in the model?
yes i do when i check database,
do you need any screenshot to make sure for my question ?
i got it now,
thank you guys
Maybe wanna share your solution for people finding this through search?
Sure
1, use HasUuids in your Model
2,in migration
$table->uuid('id')->primary()->unique()->first();