I am trying to unit test creating a company
however I don't know what the fields/attributes of the model are.
So I look in App\Company.php
, but there is no list of fields there.
Then I look at the migrations, but I have to go through each of them to find the fields available.
So as a last resort I open a DB explorer to find what fields are in the model.
Is there an easier way to know what fields exist in a model?
You can do it this way, without the need of loading any object from the db:
$fields = (new \App\Company())
->getConnection()
->getSchemaBuilder()
->getColumnListing((new \App\Company())->getTable());
Also you can:
$fields = Schema::getColumnListing((new \App\Company())->getTable()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With