Unable to locate publishable resource when adding sanctum to existing project - php

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="Laravel\Sanctum\SanctumServiceProvider"
I'm getting 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 autoload_classmap.php
Again, this was an attempt to add Sanctum to an existing Laravel project
Did I miss something?
My setup:
Laravel 8.37
PHP 7.3.9
Composer 2.0.12

I have managed to solve my problem.
Short answer:
After composer require laravel/sanctum do this:
Backup or rename cache/services.php
Remove cache/services.php
Run php artisan. Seems that running artisan in any way will regenerate cache/services.php
After that, continue with the official documentation (publish, migrate, and so on)
Longer explaination
Not entirely sure what is going on. But apparently all discovered service provider is cached in cache/services.php.
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.

Related

Deploying Laravel 5.4 to Shared Hosting

I've got a real head-scratcher for you! I've been working on a Laravel 5.4 application for quite some time now and up until yesterday I had been able to:
develop on my local machine [still works flawlessly],
push my changes to my BitBucket repo [still okay here],
and would subsequently pull those changes to my shared hosting server (RedHat) [still running smoothly],
I then run my dependency managers (npm and composer) to get the project in place and functional
there is some matter with clearing various caches:
php artisan view:clear
php artisan route:clear
php artisan cache:clear
composer dump-autoload
and finally move my '/public' folder to the web root and update index.php to point back to the 'bootstrap/autoload.php' in main project structure,
I am aware there is likely another or several steps I am missing, but I am unsure what they are...
All that being said, I've attempted to deploy a number of applications using Laravel lately and I always seem to run into the same issue come time to deploy an application to production. I've read 30+ tutorials on the matter and nothing seems to explain the issue why my site isn't working any more.
I've checked the error log file maintained by Apache, it's empty.
Was wondering if it's a permissions issue, doesn't seem to be the case (all folders set to 775 and files set to 664 as specified by various sources and owned by serverName:userName)
Browser console simply shows a 500 server error.
All I see if "Whoops, looks like something went wrong." twice.
There must be some way to show better error details (config debug setting already set to true)
Any suggestions at this point would be beneficial to send me looking in the right direction!
======= UPDATES =======
For the sake of thoroughness, and that this save others from severe headaches, I'll be posting actions taken here.
Following tutorial mentioned by #user123456 (permissions applies)
Generate new key for application
Run php artisan config:clear
Off to the races, answer to come!
You need to ensure you have a working .env file.
Once done, run php artisan key:generate to create a key for your application after which you should clear your application's cache as follows php artisan config:clear
I would never recommend using shared hosting for Laravel application. You will face lots of issues for permissions, composer and external dependencies. Instead, you can use cloud servers like DigitalOcean, Linode, vultr and deploy laravel application on them. If you don't know about linux and creating Stacks you can use Cloudways to deploy laravel.
https://dev.to/rizwan_saquib/deploy-laravel-application-on-cloud-easily-with-cloudways

Why "Class 'GuzzleHttp\Client' not found" even after Installing it in Laravel?

I've been reading answers from all the questions related to GuzzleHttp\Client but situation is getting worst. I am trying to send E-mail Updates to all of my Application users using Laravel Queues. I don't know what's wrong but Jobs are failing.
I am properly caching the Exceptions and reporting them to laravel.log file. Here is what I am getting when I try to execute queue worker.
[2018-03-23 11:43:06] production.ERROR: Class 'GuzzleHttp\Client' not found {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Class 'GuzzleHttp\\Client' not found at /home/polymath/saio/public_html/vendor/laravel/framework/src/Illuminate/Mail/TransportManager.php:181)
I've already installed GuzzleHttp\Client using composer require guzzlehttp/guzzle. It is successfully installed but still, I am getting the same error.
Even I tried to delete the current application files and clone my whole repository again. Still Facing the same issue. I even tried to clear caches using php artisan cache:clear , php artisan cache:config and php artisan clear-compiled(This made my whole application crash) , php artisan dump-autoload.
I can't find what's wrong but that's all logs say.
It seems you may need an older version of Guzzle to work with Laravel, try using Guzzle 3.x by updating your composer.json like such
"guzzlehttp/guzzle": "~3"
If you wish you can also try to use ~4 and see if Guzzle 4.x will work for you, remember to run composer update and composer dump-autoload after updating your composer.json file.
Update: This info is based on research since Laravel 4 and may be deprecated for Laravel 5.x
use GuzzleHttp\Client;
in your method Add
$client = new Client();

Issue with laravel composer

(don,t get angry with that)why we use composer i searched in google it says it is used for the dependencies of laravel, but why we create project in composer?cant we create it in simply in xampp/htdocs/laravel/... there as in past they does in codeigniter?explain it simply and clearly, what is the purpose of using the artisan commands, like php artisan serve that create a host address like localhost:8000 cant we go there in browser simply like localhost/laravelproject?and does composer works offline,without internet access,i mean entering those commands in cmd prompt?simply my concept is not clear with using composer with laravel, clear my concept...thanks
As google said, composer is always for dependencies, not just laravel but in any other framework or libraries, composer is used to automatically download dependencies needed for code to work.
Laravel is based on some packages that are some kind of third-party packages. When you create a project in codeigniter you copy all files needed for project. You can do this in laravel too, but you should have all files that are needed. Now you can download all files manually or just set those files and libraries in a file named composer and let composer do that for you. And even if there are dependencies for libraries that you mention for composer, composer detects them and downloads them too.
When you create laravel project with composer, you can save all files and use them for another project (as I did), and not to use composer again.
Artisan commands are just here to help you. Many of commands that are supported by artisan, are possible to be done by your hand, but artisan is here to help you.
Of course you can use xamp or wamp to host your laravel project, here serve command is another option to serve your project. You do not have to use it (as I never do).
Composer does not have dependencies and it just detects dependencies and downloads them.
Hope that helps.

How I can install and configure an existing Laravel Project? (Laravel 4)

I need to install and configure an existing Laravel 4 project.
I tried to do, but when I ran composer update or composer install a lot of issues appear.
I have the database too (with data) so I ran the migration but doesn't work because the console show me an issue about the "table doesn't exist".
Can anyone tell me the complete process to configure the App?.
I mean, what its first, second and so and so because maybe in some step I made a mistake
To install and configure an existing project, you'd typically
Check out its source code
Run composer install
Run php artisan migrate
Check the README for specific instructions on installing 3rd party assets, or any additional steps you'd need to take
If the above creates errors, its either because of something in your environment (installing over an old project?) or some problem with the way the Laravel developer created their project.
To install and configure an existing project, you'd typically check those things first :
You should goto app/config/database.php check file and verify username and password.
After check in Project Folder vendor folder and composer.json file exist then remove it (that remove old configuration now we going to fresh configuration).
Then after back to command prompt and fire command composer update and that download some dependent file download.
Now Run php artisan serve
that tricks work for me last time when I migrate another host.
Carlos, when using an existing DB you'll need to check the migrations table to see which migrations have run successfully. Typically when taking over a laravel project setting up a new db and running the migrations against it is a good idea because you never know what hacks were made to the database outside the migration system. One small change can throw the entire system into a useless state because it's looking for a table or column that doesn't exist or has been modified. If you run the migrations against a bare db you can also figure out which tables were manually created (which could very well be your issue) outside the system and add them in as necessary. Cobbling things together after a previous developer is tedious, hopefully there is decent documentation.
Note that if you are using Git with .gitignore, don't forget to copy .env variables in new location too.

Eloquent paginate breaks on 4.2

I am receiving the following error when using paginate with Eloquent:
Argument 2 passed to Illuminate\Pagination\Factory::__construct() must be an instance of Illuminate\View\Factory, instance of Illuminate\View\Environment given, called in C:\****\vendor\laravel\framework\src\Illuminate\Pagination\PaginationServiceProvider.php on line 23 and defined
For testing purposes, this is all I have in the method of my controller:
return User::paginate(15);
I'm aware about the upgrade procedure from the docs, but I don't have any of the references mentioned there.
Update:
In my specific case there was a package in the workbench which was requiring Illuminate 4.1 components, I changed to 4.2 in composer.json, removed the vendor dir and composer.lock file, did a composer install, and the error is gone.
These operations were all done within the package folder.
Posted as a comment, but it was the right answer:
Is there any chance you are only requiring some of the Laravel components, and not the entire Laravel framework? If you are only working with some then things like this can get out of whack, especially if not all of your components are updated to 4.2.
I encountered the same issue as you when I updated from 4.1 to 4.2, which in my case I did a composer update on my development environment before pushing and did a pull from my staging. Now the pagination issue doesn't exist in my development but in my staging, so I figured it might be the issue with git pull missed some files, or cache in the views. So I did remove the entire project and do a clean clone from the repository, that seems to fix the problem.
So not fully sure on how you update, but you might want to check that your updated files has been fully applied.
I also ran into this same problem when upgrading from 4.1 to 4.2, but my fix was different to Phil Sturgeon's.
I simply had to remove the bootstrap/compiled.php file located in the root of the Laravel project.

Categories