Class 'Socialite' not found [duplicate] - laravel

This question already has answers here:
Laravel Class Socialite not found
(9 answers)
Closed 5 years ago.
I am using Socialite package in my app. I followed all the instructions from the official github page. I am using Laravel 5.4.27. When I try to run the app, I get "Class 'Socialite' not found"error. What do I need to do??
I have also added use Socialite;, Laravel\Socialite\SocialiteServiceProvider::class, and 'Socialite' => Laravel\Socialite\Facades\Socialite::class, and I am using version 3 of socialite.
Here's the controller:
<?php
namespace App\Http\Controllers\Auth;
use Socialite;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class SocialLoginController extends Controller {
public function redirectToProvider($service, Request $request) {
return Socialite::driver($service)->redirect();
}
public function handleProviderCallback($service, Request $request) {
}
}
What do I do?

Try composer dump-autoload
composer install installs the vendor packages according to composer.lock (or creates composer.lock if not present),
composer update always regenerates composer.lock and installs the lastest versions of available packages based on composer.json
composer dump-autoload won’t download a thing. It just regenerates the list of all classes that need to be included in the project (autoload_classmap.php). Ideal for when you have a new class inside your project.
Ideally, you execute composer dump-autoload -o , for a faster load of your webpages. The only reason it is not default, is because it takes a bit longer to generate (but is only slightly noticable)
EDIT:
Also clear the config cache:
php artisan config:clear
If all this stuff do not help, try this answer (find in old stack questions like "socialite not found"):
https://stackoverflow.com/a/28451747/7155723
Hope it will help you :)

Related

Run Laravel Seeder From Package

I'm working on a package for an internal Laravel application and I'm having trouble running a seeder that exists in the package directory.
In my package's composer.json file located in packages/vendor/packagename, I've added the following:
"autoload": {
"psr-4": {
"Vendor\\PackageName\\": "src/",
"Vendor\\PackageName\\Database\\Factories\\": "database/factories/",
"Vendor\\PackageName\\Database\\Seeders\\": "database/seeders/"
}
},
I have the following file located in "packages/vendor/packagename/database/seeders/DepartmentSeeder.php"
<?php
namespace Vendor\PackageName\Database\Seeders;
use Illuminate\Database\Seeder;
use Vendor\PackageName\Models\Department;
class DepartmentSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
Department::factory()->count(10)->create();
}
}
I then attempt to run the following command:
$ php artisan db:seed --class="Vendor\\PackageName\\Database\\Seeders\\DepartmentSeeder"
Target class [Vendor\PackageName\Database\Seeders\DepartmentSeeder] does not exist.
If I move the seeders directory into my src directory and run the following, it works, but I'd rather keep my seeders in my database directory.
$ php artisan db:seed --class="Vendor\\PackageName\\seeders\\DepartmentSeeder"
Does anyone have any idea why the class isn't being found? All my Google search results are purple and I even went to page two =/
Solution
In my particular case, composer dump-autoload wasn't doing the trick. What I ended up doing was running composer update vendor/packagename and whatever the issue was, it was resolved.
Hopefully, this helps anyone else who may have similar issues.
In my particular case, composer dump-autoload wasn't doing the trick. What I ended up doing was running composer update vendor/packagename and whatever the issue was, it was resolved.
Hopefully, this helps anyone else who may have similar issues.

Cannot locate class of installed package

I'm writing a laravel package which contains spatie/laravel-sitemap.
I already included several external packages and I didn't encountered any issues, but for some reason I'm not able to integrate this one.
What I did is the usual:
composer require spatie/laravel-sitemap
Then I have created a Console command that have as handle method the following content:
public function handle()
{
SitemapGenerator::create(config('app.url'))
->configureCrawler(function (Crawler $crawler) {
$crawler->ignoreRobots();
})
->writeToFile(public_path('sitemap.xml'));
$this->line('<info>Sitemap generated');
}
when I execute the command registered as:
php artisan myapp:sitemap
I get:
Class "Spatie\Sitemap\SitemapGenerator" not found
The reference imported are:
use Spatie\Crawler\Crawler;
use Spatie\Sitemap\SitemapGenerator;
I also tried composer update and composer dump-autoload, same problem.
Any help?
register package class in providers array in config/app.php
Spatie\Sitemap\SitemapServiceProvider;
in the bottom of app.php file
i hope it was useful.
you can publish package using this.
php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=sitemap-config
then
composer dump-autoload
for more details please check the document https://github.com/spatie/laravel-sitemap under Configuration

Service Provider not booting in Laravel 5.8

I've created a new service provider to observe a model (App\Providers\EloquentEventServiceProvider.php), like so:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Staff;
use App\Oberservers\StaffObserver;
class EloquentEventServiceProvider extends ServiceProvider
{
public function boot()
{
Staff::observe(StaffObserver::class);
}
}
I've also added it to the config file (config\app.php):
return [
...
'providers' => [
...
App\Providers\EloquentEventServiceProvider::class,
...
]
...
]
The observer methods aren't working though. If I move Staff::observe(StaffObserver::class); to the AppServiceProvider class, it works just fine. So clearly this is an issue with getting my service provider to boot. I've tried php artisan config:clear, php artisan clear-compiled, composer update and composer dump but none have work. Any help is greatly aprpeciated.
your Oberservers name is wrong, as mentioned in the laravel doc observers laravel doc it should be Observers which means all of your observers should be within App\Observers instead of App\Oberservers.
so here we have 2 solutions :
1- if you want to keep the namespace App\Oberservers, you should run these 2 commands below because autoloading of the files may not work properly because we created a new folder Oberservers:
# Autoloading of files
composer dump
# Configure the cache
php artisan config:cache
2- the second solution is to just rename your actual Oberservers folder to Observers, in that way the autoloading of files will work well.

Class 'Tests\DuskTestCase' not found in ExampleTest.php

I am trying to run Laravel Dusk tests, but when I run the test, a new Chrome tab pops up with this message.
Fatal error: Class 'Tests\DuskTestCase' not found in path-to-project\tests\Browser\ExampleTest.php on line 9
All I have done so far is run composer require --dev laravel/dusk:^1.0 and php artisan dusk:install.
This is my ExampleTest.php (exactly how Laravel set it up)
<?php
namespace Tests\Browser;
use Laravel\Dusk\Chrome;
use Tests\DuskTestCase;
use Laravel\Dusk\DuskServiceProvider;
class ExampleTest extends DuskTestCase
{
/**
* A basic browser test example.
*
* #return void
*/
public function testBasicExample()
{
$this->browse(function ($browser) {
$browser->visit('/')
->assertSee('Laravel');
});
}
}
DuskTestCase.php is also just as Laravel set it up and has the namespace namespace Tests;.
I am using Laravel 5.4 and Dusk 1.0. I am running the test through PhpStorm, using the work around described here.
Anyone know why DuskTestCase can't seem to be found, even though it appears to be set up correctly? Thanks in advance.
In composer.json:
add "Tests\\": "tests/" in
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Tests\\": "tests/"
}
},
then, run composer dump-autoload to reload your packages.
I had this error due to using out-of-date docs that didn't include this line:
$ php artisan dusk:install
If composer dump-autoload does not solve problem, you can try these steps.
Visit homepage in your browser and check if it renders properly. If not, then you probably have a problem with your webserver configuration (Hint: isn't your project subdirectory of document root?).
You can try Laravel inbuilt server via php artisan serve. If homepage is accessible in your browser now, then you can try dusk again.
In that case, remember to update your .env file to match APP_URL=http://127.0.0.1:8000,
and run php artisan dusk from another cli window, cause php artisan serve needs to be running also.
if you test using a phpstrom then u have set path of phpunit ......
in settings/languages & framework/php/test frameworks and use composer autoloader path and then select a path of your laravel dusk project with autoload.php file.....
set file a vendor/autoload.php file in path to script...

CodeIgniter + omnipay installation

I have used ci-merchant before but from everything see that the "V2" of it is now omnipay. I use codeigniter and i'm struggling to get even the example to work.
I have installed omnipay no problems and in my controller have the following:
use Omnipay\Common\GatewayFactory;
class Homepage extends BC_basecontroller {
public function index()
{
$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername('adrian');
$gateway->setPassword('12345');
}
}
Which is the example here: https://github.com/adrianmacneil/omnipay
However I get the error:
PHP Fatal error: Class 'Omnipay\Common\GatewayFactory' not found in......
Does anyone know how to get it to work in CI?
I'm not sure how you installed Omnipay, but you need to use Composer to load the classes before you can use them.
So following the Omnipay installation instructions, add this to a composer.json file in your root directory:
{
"require": {
"omnipay/omnipay": "*"
}
}
Then install the files:
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update
Now, if you are using CodeIgniter you will need to set it up to include the composer autoloader. Basically, just add this line to the top of your index.php file:
require_once __DIR__.'/vendor/autoload.php';
There is also a tutorial on using Composer with CodeIgniter here which you may find helpful: http://philsturgeon.co.uk/blog/2012/05/composer-with-codeigniter
I had the same error and fixed it by loading vendor/autoload.php before application/core/CodeIgniter.php

Resources