Create Model for already existing table
Hi there,
I would like to create an admin panel for a database table which already exists.
For non-existing tables, I create a migration, where the database structure is defined.
The table is created in the database when I run artisan migrate.
But if the table already exists, things are somewhat different.
There will not be a migration in this case, since the database must not be dropped and re-created.
But how does Laravel "know" how the table looks like?
How does Laravel "know" the name of the table it should read and/or modify with this admin panel?
I would like Laravel to create the ressources for me. Can that be done?
Kind regards,
Tom
7 Replies
You can auto generate
But still laravel project must have models
I can auto-generate the tables and the ressources when I first create the migration. But I would like to create the model based on an already existing db table and have no migrations.
artisan make:model
then if the model and db table names don’t follow normal Laravel conventions you can always define which table to use as a property on the model. It’ll just work.
Of course you’ll want to do all the fillable and casts by hand.ok, I think I understand. I'll try that! Thanks!
Better check laravel docs