Is there any possible way to generate database from models in Laravel ? I am working on an existing laravel project,it contains models without their migrations.
I tried the reliese/laravel also the doctrine but nothing won't work ..any help ?
Is there any possible way to generate database from models in Laravel ? I am working on an existing laravel project,it contains models without their migrations.
I tried the reliese/laravel also the doctrine but nothing won't work ..any help ?
Suppose you have model User
without migration then you can get table name from it like
User::getTableName();
there is same function to get column names and you can get column types from protected $cast = []
Here is Sample code
$location = new LocationTable(); // load your model
$tableName = $location->getTable(); // this will give a table name from your model
$columnsWithType = $location->getCasts(); // set all your table fields as cast
Schema::create(tableName , function (Blueprint $table) use ($columnsWithType) {
foreach ($columnsWithType as $columnName => $type) {
$table->$type($columnName);
}
});