如何卸载 Laravel Passport
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47567249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to uninstall Laravel Passport
提问by zhekaus
I've decided to use JWT and completely remove Laravel Passport from the project.
我决定使用 JWT 并从项目中完全删除 Laravel Passport。
I was trying to start with composer remove laravel/passport. However, it does no good:
我试图从composer remove laravel/passport. 但是,它没有好处:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Laravel\Passport\Passport' not found
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1
Removal failed, reverting ./composer.json to its original content.
What could be the right and safe removing procedure?
什么是正确且安全的移除程序?
回答by Paul Santos
You can remove passport by manually deleting this line "laravel/passport": "^4.0"in your composer.jsonfile then run composer update.
您可以通过手动删除这一行删除护照"laravel/passport": "^4.0"在你的composer.json文件,然后运行composer update。
If you're running Laravel 5.4 or below, make sure to remove this line in your app.configfile Laravel\Passport\PassportServiceProvider::class
如果您运行的是 Laravel 5.4 或更低版本,请确保删除app.config文件中的这一行Laravel\Passport\PassportServiceProvider::class
And all classes that relies on passport must be edited as well. The most common classes are:
并且所有依赖于护照的类也必须进行编辑。最常见的类是:
Usermodel, remove theHasApiTokentrait.AuthServiceProvider, removePassport::routes();in your boot method.- Your
config/auth.php, change your driver option forapiauthentication
User模型,删除HasApiToken特征。AuthServiceProvider,Passport::routes();在您的启动方法中删除。- 您的
config/auth.php, 更改用于api身份验证的驱动程序选项
回答by Sawan
After following Paul's steps. Remove the Passport Migrations in database migrations table and run command artisan migrate:refresh.
在跟随保罗的步骤之后。删除数据库迁移表中的 Passport Migrations 并运行命令artisan migrate:refresh。
回答by DevonDahon
With Laravel 7, I did it this way:
使用Laravel 7,我是这样做的:
Step 1.In app/Providers/AuthServiceProvider.phpfile remove these two lines:
步骤 1.在app/Providers/AuthServiceProvider.php文件中删除这两行:
use Laravel\Passport\Passport;
Passport::routes();
Step 2.
第2步。
$ composer remove laravel/passport
$ rm -r ./resources/js/components/passport # if any
$ rm -r ./resources/views/vendor/passport # if any
Step 3.In the file resources/js/app.js, remove passport components registration. You may also find and remove these registered components if you used it somewhere:
步骤 3.在文件中resources/js/app.js,删除护照组件注册。如果您在某处使用过这些注册组件,您还可以找到并删除这些组件:
$ grep -rn 'passport-authorized-clients' resources/js/*
$ grep -rn 'passport-personal-access-tokens' resources/js/*
$ grep -rn 'passport-clients' resources/js/*
Step 4.Find and remove HasApiTokensfrom your models:
步骤 4.HasApiTokens从您的模型中查找并删除:
$ grep -rn HasApiTokens *
Remove also the import line going with it:
也删除随之而来的导入行:
use Laravel\Passport\HasApiTokens;
Step 5.Remove oauthkeys
步骤 5.删除oauth密钥
$ rm storage/oauth-*.key
Step 6.In the file config/auth, revert the apidriverin guardsfrom passportto token.
步骤 6.在文件中config/auth,将apidriveringuards从恢复passport为token。
Step 7.Drop Passport tables and clean migration table
步骤 7.删除 Passport 表和清理迁移表
$ php artisan tinker
>>> Schema::drop('oauth_access_tokens');
>>> Schema::drop('oauth_auth_codes');
>>> Schema::drop('oauth_clients');
>>> Schema::drop('oauth_personal_access_clients');
>>> Schema::drop('oauth_refresh_tokens');
>>> DB::table('migrations')->where('migration', 'like', '%_oauth_access_tokens_table')->delete();
>>> DB::table('migrations')->where('migration', 'like', '%_oauth_auth_codes_table')->delete();
>>> DB::table('migrations')->where('migration', 'like', '%_oauth_clients_table')->delete();
>>> DB::table('migrations')->where('migration', 'like', '%_oauth_personal_access_clients_table')->delete();
>>> DB::table('migrations')->where('migration', 'like', '%_oauth_refresh_tokens_table')->delete();
>>> exit
Step 8.And finally, refresh your installation:
步骤 8.最后,刷新您的安装:
$ composer dump-autoload
$ php artisan optimize:clear
$ npm run dev

