V
V
Volodymyr2022-04-17 20:58:08
Laravel
Volodymyr, 2022-04-17 20:58:08

How to create a table for just one record in Laravel?

Hello!

How to create a table for just one record in Laravel?

I created the everythings table, it has the fields id, title, url, key, created_at, updated_at, this table will always use only one record.
And now, when requesting data, it is necessary to take data every time through Everything::find(1), how correct is this?

Or better, if a whole table is used for one record, use separate rows for each data, for example:

id   set_key    set_value
1    title      Test
2    url        https://test.com
3    key        89237rwfohsj

And then get everything via Everything::get()

How to properly use a table for one record?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
TheAndrey7, 2022-04-17
@TheAndrey7

And now, when requesting data, it is necessary to take data every time through Everything::find(1), how correct is this?

As long as there is a guarantee that this entry has an ID of 1. Some kind of first() should be used to select the first entry that comes across without being tied to an ID.
It is impossible to give an exact answer to the question without understanding what the table is used to store and how often the structure of the fields of the model associated with it will change.

L
lil_koi, 2022-04-17
@lil_koi

and why it is impossible to take out this data in .ENV?

P
pLavrenov, 2022-04-18
@pLavrenov

If the entry is really one, then you can output the file to the config (config values ​​\u200b\u200bcan be changed from the code)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question