How do you know what fields are in a Laravel Model?
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()));
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?