S
S
Sergei Gurdjiyan2017-10-16 23:05:18
MySQL
Sergei Gurdjiyan, 2017-10-16 23:05:18

How to get specific related table record by field in Laravel?

59e510ef08a14817517889.jpeg
or a link to the screenshot
1. The Page model has appends - this is the output of additional fields for pages
2. The pages table
3. The fields table, where advanced_name is a string with a unique name for the additional field and advanced_type is the type of this field
4. Translation table for fields.
5. Output of additional fields for the page.
Question:
How can I get rid of such an explicit indication of additional fields in the model, i.e. or get away from appends or make adding these attributes to the model dynamic?
Or
Each Page instance will have its own fields. Those. its collection of additional attributes.
How can I get them directly from the advanced_name field?
I hope I have made my problem clear.
Each page can have an unlimited number of additional pages. fields. Listing all of them in the model as appends is stupid. I'm looking for a universal solution.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stalker_RED, 2019-07-15
@korshunov2110

UPDATE myTable -- обновить таблицу myTable
  SET money = money + 42 -- добавить 42 денег
  WHERE id_vk = 1234567 -- для тех записей где id_vk = 1234567

Александр, 2019-07-15
@Captain

I would suggest making another plate with the history of changes in user accounts. To whom how much has come, how much has gone. By summing it, you can calculate the balance. It will be more comfortable in the end. And then you get confused with support, because you won’t remember to whom, when and what was charged.
Well and generally about SQL to esteem.

V
Vyacheslav Plisko, 2017-10-17
@mrKorg

1. You definitely don't need Appends, demolish everything.
2.1 If they are tied to a specific page (as it is now, judging by the page_id), then these fields fall into the relay already described in fileds. You can get them by $page->fileds filtering by advenced_name e.g. $page-> fileds-
>byKey('advenced_name')['about-text-1']
inject them into the model or use it as a separate model since it is not related in any way. And that at you now is dragged on each field by request from basis.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question