How can I create migration file from existing model in Laravel or model from existing migration?
How do you make a controller model and migration in one command in Laravel? Navigate to your project folder and run the following commands to create new: Model: php artisan make:model YourModelName. Controller: php artisan make:controller YourControllerName.
To create a table for a existing Model, you just have to run below command,
php artisan make:migration table_name
and, go to the database -> migration -> date_with-table_name
inside up()
, type your table name and fields that you want to add, something like belowa;
Schema::create('table_name', function (Blueprint $table) {
$table->increments('id');
$table->string('field_2');
$table->string('field_3');
$table->string('field_4');
$table->date('field_5');
$table->string('field_6');
$table->timestamps();
});
read more here.
For the model, just create a model, there isn't anything special, just make sure to set the $table
if not following convention.
For generating migrations from an existing Database schema there is a package:
Xethron - Laravel Migration Generator
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