Source: tony-stark.medium.com

Laravel Generate Model from Database Table

Category: Laravel, Laravel

In this article, I will show you how to generate an Eloquent Model from a database table.

Step Add Eloquent Model Generator to your project: Step Register GeneratorServiceProvider: If you are using Laravel version 5.5 or higher this step can be omitted since this project supports Package Discovery feature. Step Configure your database connection.

Use table-name option to specify another table name: In this case generated model will contain protected $table = 'user' property.

Add next lines at your config/eloquent_model_generator.php: Table user: Command: Result: If you use this package code generator automatically generates doc for your models.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners