The Laravel Sanctum documentation states that to add Sanctum to existing Laravel project one has to:
- Require Laravel Sanctum
composer require laravel/sanctum
- Publish Sanctum’s resources to app dir
php artisan vendor:publish --provider="LaravelSanctumSanctumServiceProvider"
Unable to locate publishable resources. when running (2)
I already tried
php artisan clear-compiled and
composer dumpautoload in that order
I checked that
vendor/laravel/sanctum/src/SanctumServiceProvider.php exists and the boot() method does publishes Sanctum’s config and migration
I also checked that SanctumServiceProvider is discovered by autoload by making sure that the source path is listed in
Again, this was an attempt to add Sanctum to an existing Laravel project
Did I miss something?
- Laravel 8.37
- PHP 7.3.9
- Composer 2.0.12
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
I have managed to solve my problem.
composer require laravel/sanctum do this:
- Backup or rename
php artisan. Seems that running artisan in any way will regenerate
After that, continue with the official documentation (publish, migrate, and so on)
Not entirely sure what is going on. But apparently all discovered service provider is cached in
I don’t know how it’s being generated and how service providers get discovered. Googling doesn’t yield me any documentation regarding that file (official or otherwise).
I figured I if I add Sanctum’s SP to
config/app.php (i.e. the documented way of adding service provider) it will get discovered and cached. Apparently that wasn’t the case. Removing and regenrating
cache/services.php is the only way I found working. After the file was regenerated, Sanctum’s SP is listed.
One thing I observe was that this only happens on an existing project (existing as in already being worked on, packages added, config changes and so on). Doesn’t happen if I add Sanctum to a fresh project.