How do you know which fields are in the Laravel model?

I am trying to create a unit test company, but I do not know what fields / attributes of the model.

So I look App\Company.php, but there is no list of fields.

Then I look at the migrations, but I need to go through each of them to find the available fields.

So, as a last resort, I open the DB Explorer to find which fields are in the model.

Is there an easier way to find out which fields exist in the model?

+4
source share
3 answers

You can do it this way without having to load any object from db:

$fields = (new \App\Company())
->getConnection()
->getSchemaBuilder()
->getColumnListing((new \App\Company())->getTable());

You can also:

$fields = Schema::getColumnListing((new \App\Company())->getTable()));
+4
source

- getAttributes() .

.

+4

I would look for database table migration (in database/migrations/). If there is no migration, I would go to anwser @Luceos.

0
source

Source: https://habr.com/ru/post/1620741/


All Articles