Access $record in resource

Hi, I'm trying to get the data from the database row I'm working on using resources, in this case ProjectResource, I tried to get it with mount(), but I can't get it, how can I do it?
23 Replies
David Gil
David GilOP9mo ago
I know, in view mode I can use it, but I want to get it in edit resource, when creating a form.
David Gil
David GilOP9mo ago
No description
Tieme
Tieme9mo ago
So on the Create and Edit form you want it? Because i think the Resource page is not a single record page.
David Gil
David GilOP9mo ago
Only in edit
awcodes
awcodes9mo ago
You can’t do that in the Resource class. You need to do it in the EditProject class. And it’s probably $this->getRecord() or $this->record, make sure to use parent::mount() in your mount function though otherwise it won’t work.
David Gil
David GilOP9mo ago
No description
David Gil
David GilOP9mo ago
No description
David Gil
David GilOP9mo ago
This is the function defined in the parent by default in EditRecord, should I overwrite it?
awcodes
awcodes9mo ago
You can if you call parent::mount() first in your override. Question is, is that the appropriate place for your needs. I’m still not sure exactly what your goal is. 😀
public function mount(): void
{
parent::mount();
// do extra logic
}
public function mount(): void
{
parent::mount();
// do extra logic
}
David Gil
David GilOP9mo ago
Maybe for my purpose, this is not necessary then, I in my case, what I do in the Resource form, both to create and to edit, is to create an own Hexadecimal Id, without repeating it, but every time I update it changes, so I want to check the id (id that is created with the table) so that it does not generate it in case of editing
awcodes
awcodes9mo ago
Sorry, not following.
David Gil
David GilOP9mo ago
I generate an id, which is not the same as the id of the table, but has to be unique. So, what I wanted to do is to get a $record of my project when editing, so that it doesn't generate it for me. And in case it is Create, it will create it for me.
No description
awcodes
awcodes9mo ago
Something feels off here. Wouldn’t $record be the project? So why do you need an id before it’s even created. The form lifecycle hooks might be a better place to handle this. Also hidden fields for anything id related is probably a bad idea since it can be manipulated on the frontend.
David Gil
David GilOP9mo ago
I don't know what you mean with that As for the other thing, I know it's not a good idea, but for this particular project it's an id that is not as sensitive as the table id I thought that if I wanted to create a function with its own ID it would have to be there
awcodes
awcodes9mo ago
Maybe that’s where I’m getting confused. What is the difference between the two ids? What is the need for a secondary identifier?
David Gil
David GilOP9mo ago
It is the same, but the identifier is one of its own, as if it were a name Where should I create it from otherwise, being from the resources form where I create the form?
awcodes
awcodes9mo ago
I don’t see why it’s needed. Everything in the system should just reference its table id. Even if that is is a uuid or ulid. What do you actually need the secondary id for? Where is it applicable or needed in order to reference the record.
David Gil
David GilOP9mo ago
It's really like a name identifier, but generated automatically, and with hexadecimal
awcodes
awcodes9mo ago
Still, why does it need a name identifier? Maybe that’s what I’m getting at.
David Gil
David GilOP9mo ago
This is something that the client has asked me to do in order to make it more comfortable for him
awcodes
awcodes9mo ago
So wouldn’t that just be a column on the record in the db? Then you can set it when the record is actually created. It shouldn’t change after that. And you can use the create life cycle hooks to do that or an observer might be better.
David Gil
David GilOP9mo ago
Ok, I'll try it the other way Thank you very much for your help and patience 😄
Want results from more Discord servers?
Add your server