欢迎各位兄弟 发布技术文章
这里的技术是共享的
php artisan make:model modelname
And that will create a model under app
folder, and also a migration in database/migrations
But what I can't find is how to delete a model...
正确答案
Deleting a model: just delete the model under App/
or whatever other folder.
Deleting a migration: if you have migrated it (meaning the database has suffered changes) you have two choices:
The "project starting"/ugly way is to migrate:rollback
until the migration is undone (if it was the last migration you did, one rollback is enough, if not, you're gonna have to rollback a couple of times) then delete the migration file (the one inside the database/migrations
folder. Important thing here: the migration's class will still be autoloader by composer. So you have to remove the migration class loading from vendor/composer/autoload_classmap.php
. Maybe composer dumpautoload
will work, it didn't for me though. If you have no important data in the DB and you can wipe it, delete the migration file, composer dumpautoload
then run php artisan migrate:refresh
. This will rollback every migration then migrate everything back in.
The "this is in production and I messed up" way: create another migration where the up method is dropping the first migration's table, down is creating it (basically the up method from the first migration). Leave the two migration files in there, don't remove them.
If you haven't migrated it, just delete the migration file, composer dumpautoload
and if you have some class/file not found
error, check if vendor/composer/autoload_classmap.php
has the class of the file you just removed and delete the row there.
来自 http://stackoverflow.com/questions/30517098/how-to-delete-a-model-using-php-artisan
我对Laravel 5.1有简单的问题。我已经使用php artisan命令创建了一个控制器:
php artisan make:controller PageSettings
但是这是错误的,因为我真的想在Admin文件夹中创建这个控制器,如下所示:
php artisan make:controller Admin/PageSettings
现在我想摆脱我旧的PageSettings控制器。是否只是删除我的旧的PageSettings.php手册?还有更多的东西需要做什么?
正确答案
如果你只创建它,发现你做错了,你可以手动删除文件,就是这样。但是,当您已经添加到此控制器的路由时,routes.php
您应该将其从routes.php
文件中删除或更改文件以反映您的新控制器。
来自 http://stackoverflow.com/questions/34692667/laravel-5-1-remove-controller