Class Sheets not found - php

Hey guys I have integrated Google sheets using revolution/laravel-google-sheets following this blog https://drivemarketing.ca/en/blog/connecting-laravel-to-a-google-sheet/
Everything works well on my development environment so I have pushed my code to my staging server to test. After pushing my code to the staging server, I ran the following commands composer update, php artisan config:cache and composer dump-autoload in that order. When I test the flow, I get an exception error
ERROR: Class 'Sheets' not found {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0):
Below is a snippet of the controller code
<?php
namespace App\Http\Controllers\API;
use Sheets;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class MainController extends Controller
{
/**
* Write user details to google sheet
*
* #param $user
*/
public function writeUserToSheets($user)
{
Sheets::spreadsheet('google sheet id')->sheet('users')
->append([
[$user->id, $user->email, $user->first_name, $user->last_name, $user->created_at->toDateTimeString()]
]);
}
}
Am I missing anything? How do I get my code to work on my staging server?

Related

Fatal error: Class 'TestCase' not found in laravel 9

I updated my project from laravel 8 to laravel 9 then I tried to make a test case generated by artisan.
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class SimpleTest extends TestCase
{
/**
* A basic feature test example.
*
* #return void
*/
public function test_example()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
But when I run phpunit I always get this error
PHP Fatal error: Uncaught Error: Class "Tests\TestCase" not found in path/to/SimpleTest.php:9
How can I fix this?
I created fresh Laravel 9 app to investigate this case.
Apparently the content of TestCase.php in my app was different from the one in fresh app. So I replace TestCase.php file with the one from fresh app and it works now.

Laravel default helper method and facade doesn't work on custom package

I am developing a custom package where I need an access to the config data. I was able to pull data from config through my blade files, however, when I tried to call it from any custom classes I made, it's throwing an error:
Error: Call to undefined function Acme\Package\config()
What's interesting though, is that, when I tried using the facade Illuminate\Support\Facades\Config, it cannot find the class.
Is there any way I could retrieve data from the config (from the package and/or the app)?
<?php
namespace Acme\Package;
class MyClass {
public function test() {
config('app.name');
}
}
UPDATE: It works when running in the browser (package installed in a Laravel project) but fails when running package's test
UPDATE: If this helps, my package can be found here
Call to the config() is from here
And the test case that fails can be found here
<?php
namespace Acme\Package;
class MyClass {
public function test() {
\Illuminate\Support\Facades\Config::get('app.name');
}
}
Try like this, to use the full namespace to the Config Facade. You could also make a use statement under your namespace to inject the facade and then use Config::get('app.name). The reason it is not working is that your package cannot resolve the namespace of that facade as it is outside of the IoC container
You should try this:
<?php
namespace Acme\Package;
use Config;
class MyClass {
public function test() {
Config::get('app.name');
}
}
Updated answer
Please add below line in config/app.php in aliases section
'Config' => Illuminate\Support\Facades\Config::class,
then run below command
php artisan config:cache
php artisan cache:clear

Symfony 2 namespace error only in production ("Attempted to load class...)

I am working on a Symfony 2 website, and having an issue only in production (cache is clear).
I am using the Payplug php api : I' ve put the files in the vendor folder, I use the namespace for the classes I use, and everything is ok on my local dev environment.
Once on the prod server, I get the error:
"Attempted to load class "Payplug" from namespace "Payplug". Did you forget a "use" statement for another namespace?"
I don't get why it gets a namespace error only on the prod server...
CONTROLLER :
<?php
namespace KpmBundle\Controller;
use KpmBundle\Entity\Marche;
use KpmBundle\Entity\Marcheur;
use KpmBundle\Entity\Commande;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Payplug\Payplug as Payplug;
use Payplug\Payment as Payment;
class MarcheController extends Controller
{
//code
Payplug::setSecretKey(...);
//more code
}
CLASS
<?php
namespace Payplug;
/**
* The Payment DAO simplifies the access to most useful methods
**/
class Payment
{
I really wonder why everything works fine on my local dev server ( app_dev.php and app.php ), but goes wrong on prod server...
Any idea would be appreciated,
regards
EDIT
The files where installed via composer
I was using FTP, and transfered the vendor\payplug directory alone to the remote server ; as a result the vendor\composer wasn't sync between local and remote server.
transfering the local vendor\composer solved the problem
Thx to #cerad

Laravel Passport routes missing in route:list - 404 error on oauth/token

I have followed the Laravel 5.5 documentation to require, install and configure Laravel Passport on our application. We are ONLY using the password grant functionality as we aren't intending to use this as a social login tool. However, after following all the instructions, I am getting a 404 error when attempting to POST the form data into the application using Postman.
I have run php artisan route:list and there is no mention in there of oauth at all. I'd share the output but it's quite long as we have a large application.
I have ensured that Passport::routes() is in the AuthServiceProvider as shown below:
<?php
namespace App\Providers;
use Laravel\Passport\Passport;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* #var array
*/
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* #return void
*/
public function boot()
{
$this->registerPolicies();
Passport::routes();
//
}
}
The documentation on 5.5 does not say anything about adding a line to the config/app.php file as previous versions of Laravel do. After getting the 404 errors I decided to try adding that line just to see if it helps. It does not.
I did in fact run php artisan passport:install and then php artisan migrate which resulted in the creation of 2 clients: (ID = 1: Personal Access Client) and ID 2: Password Grant Client) and the various oauth tables being created in our database.
The resulting 404 error IS in fact coming from the site and not some generic message as it has our theme wrapped around it so I know it's hitting the application.
I have searched for references to the 404 error on oauth/token and Laravel Passport but have come up dry on solutions.
Any suggestions are greatly appreciated.
bingo bango I found the problem....
So after digging around, as mentioned in my comment above, the AuthServiceProvider in my App\Providers folder was not referenced. I had commented out the Illuminate one and added my App\Providers one thinking that it would simply extend the Illuminate one. That caused the Auth class error. I re-enabled the Illuminate one and left my App\Providers\AuthServiceProvider enabled but below the Illuminate one and it all worked out. No more 404s... Hope this helps someone else.
I had also the same problem and fixed with clearing the caches php artisan o:c
Check that you have the correct Passport version for Laravel:
composer require laravel/passport:~4.0
for Laravel 5.5 and 5.6

Laravel 5: class 'Illuminate\Database\Seeder' not found

Problem I'm currently facing to has been posted here already, yet none of them could solve my one.
I'm talking about database seeder located under url like http://HOSTNAME/laravelfiles/database/seeds/UsersTableSeeder.php. Its content is as follows:
<?php
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
// What should be being done, it is being done here :)
}
}
Having opened this file directly (by url given above the code), following error is printed:
Fatal error: Class 'Illuminate\Database\Seeder' not found in /var/www/laravelfiles/database/seeds/UsersTableSeeder.php on line 6
I found possible solution. Doesn't work for me:
composer dump-autoload
<?php
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
{
}
NOTE: Even the code above produces the same error.
You must run seeder class via command line, not browser.
you should open your command line and change directory to laravel root folder.
then you need to run command:
php artisan db:seed
and check your database.
for more info please check laravel documentation(Laravel Database Seeding)

Categories