Let's say you have a migration with this name 2020_04_19_180238_create_doctors_table
.
To create the model and controller to this migration file just run the command bellow:
php artisan make:model Doctor -c
Note that the migration creates a table named doctors
on plural but the model file is singular doctor
.
Hope it helped
Thanks, it is very helpful ... but I have a file "2020_04_15_000169_create_productos_especiales_table.php" and I execute the following command: "php artisan make: model Jobs -c" and it only creates the controller for me, but without any methods inside, it doesn't create the model, what I want is for you to create a simple CRUD, that is, controller and model with the basic methods of created, deleted, modified and edited, is there a way to do it in some simple way? Or what is the most recommended way if I have the migration files of a 200 tables project, I want to create a simple CRUD for each one of them tables from the migration files!
Thank you
Hi @Sgvolp once again!
You mentioned that when you run php artisan make:model Jobs -c
it only generates the Controller, hummm🤔 that is an unexpected result. Model files stay under app
folder.
For the migration you mentioned on the example you should be generating a model with ProductosEspeciales
.
By the way, you don't need exactly to have model and migration files to have the same name, or be name compatible on anything like that. Tha is only a pattern you will see everywhere, but you can specify the table name in the model if you wish, by just adding:
protected $table = "the_table_name";
.
When you create a model for a table, Laravel adds all the Crud methods you may need and much more in the model. But for the Controllers you will have to write them yourself.
I think you're overthinking this due to low knowledge of Laravel. My recommendation for you is to watch some tutorials online and have some basic knowledge how Laravel works before proceeding with this task.
Laracasts has a free serie on Laravel 6 that will help you understand the core concepts of how thr framework works.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community