I followed this documentation and I keep getting that main(): Failed opening required 'vendor\autoload.php' error and I ran composer install but still get the same error. I'm using Laravel and I'm calling this from a Controller..
namespace App\Http\Controllers;
require 'vendor/autoload.php';
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Google\Cloud\Speech\SpeechClient;
use Google\Cloud\Speech\StorageClient;
use App\Model\FilesModel;
use Illuminate\Support\Facades\DB;
class FilesController extends Controller
{
private $project_id;
private $speech;
private $options;
private $storage;
public function __construct()
{
$storage = new StorageClient([
'keyFile' => json_decode(file_get_contents(public_path() . '/key.json'), true)
]);
....
How do I bypass this issue?
first of all no need to do that! because it's included in all pages...
if you insist doing this I think the problem is the address of autoload file which have to be:
require '../vendor/autoload.php';
I solved deleting the "require '../vendor/autoload.php';" sentence from Controller and works in bouth environments (local and server). I am working with an Openpay integration.
That was hard for me, because i was trying to solve editing the routes or updating composer and stuff like that.
Related
I am using PHP 7.4.1 and Laravel Framework 6.20.16.
I am trying to implement the following library: telegram-bot-sdk and the following version "irazasyed/telegram-bot-sdk": "^2.0",
After installing the sdk and getting my private token from telegram's #botfather. I am trying to use the sdk.
I created a route and a controller:
route
Route::get('telegramHello', 'TelegramController#getHello');
controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Telegram\Bot\Api as Telegram;
use App\Helpers\TelegramResponse as Response;
class TelegramController extends Controller
{
public function getHello() {
$api = new Telegram(); // ----> HERE I GET THE ERROR
$response = $api->getMe();
return Response::handleResponse($response);
}
//...
When opening my route I get the following exception:
The thing I do not understand is that I have created the config telegram.php and loading my correct token from my .env file:
In my .env file it looks like the following:
Any suggestions what I am doing wrong?
I appreciate your replies!
Use Facade, not original API class. Your config is correct, you just using wrong class.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Telegram\Bot\Laravel\Facades\Telegram;
use App\Helpers\TelegramResponse as Response;
class TelegramController extends Controller
{
public function getHello() {
$response = Telegram::getMe();
return Response::handleResponse($response);
}
//...
Also i may recommend you using westacks/telebot instead of irazasyed/telegram-bot-sdk. I created it as irazasyed's was poorly documented and really buggy at a lot of places.
The two comments above helped me the most:
Use "" for your TELEGRAM_BOT_TOKEN
Instead of using your own named .env variable use TELEGRAM_BOT_TOKEN
I hope this works also for others that have this problem.
I have a problem running tests in my laravel app.
My app is splitted into separated namespaces. Laravel App namespace is in app directory and it's App/ namespace. I have additional namespace in src directory.
My TestCase look like that:
<?php
namespace Tests\Unit;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPUnit\Framework\TestCase;
use SmoothCode\Sample\Domain\User\User;
use SmoothCode\Sample\Domain\User\UserRepository;
use SmoothCode\Sample\Domain\User\ValueObject\ConfirmationCode;
use SmoothCode\Sample\Shared\ValueObjects\Email;
use SmoothCode\Sample\Shared\ValueObjects\Id;
use SmoothCode\Sample\Shared\ValueObjects\Password;
use Tests\CreatesApplication;
class UserDomainTest extends TestCase
{
use CreatesApplication;
protected UserRepository $userRepository;
public function testUserCreation() {
$user = User::create(
Id::generate(),
'Jan',
'Kowalski',
new Email('test#test.com'),
'123123123',
new Password('Pass123!'),
new \DateTimeImmutable(),
ConfirmationCode::generate()
);
//
// $this->assertInstanceOf(User::class, $user);
}
protected function setUp(): void
{
parent::setUp();
}
}
After running vendor/bin/phpunit I'm getting following error:
1) Tests\Unit\UserDomainTest::testUserCreation
RuntimeException: A facade root has not been set.
/home/jakub/Development/Projects/streetboss-server/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:258
/home/jakub/Development/Projects/streetboss-server/src/Sample/Shared/ValueObjects/Password.php:15
/home/jakub/Development/Projects/streetboss-server/tests/Unit/UserDomainTest.php:29
From that i know that the problem lies in src/Sample/Shared/ValueObjects/Password.php:15
which looks like:
<?php
namespace SmoothCode\Sample\Shared\ValueObjects;
use Illuminate\Support\Facades\Hash;
use Webmozart\Assert\Assert;
class Password {
protected string $hash;
public function __construct($plainPassword)
{
Assert::minLength($plainPassword, 6);
$this->hash = Hash::make($plainPassword);
}
public function hashedPassword()
{
return $this->hash;
}
}
I was trying to run:
php artisan config:cache
php artisan cache:clear
php artisan config:clear
composer dump-autoload
But I'm still getting this error.
Okay, I have found a solution for this error. For anyone who would have same problem:
My UserDomainTest was extending TestCase from namespace:
use PHPUnit\Framework\TestCase;
when I've changed to:
use Illuminate\Foundation\Testing\TestCase;
everything works like a charm.
The Jakub's answer don't work for me, so I will explain what I do.
I have the file App/BusinessRules/Admin/Tests/EnvTest.php.
Even using anyone of this 2 namespaces the fail occurs.
So in my EnvTest I extend the tests/TestCase.php file from the namespace:
use Tests\TestsCase
Recently I learn Laravel and try to implement BingAds SDK to grab some reports to my database but failed.
I have a controller named BingAdController.php in app/http/Controllers/BingAdController.php
BingAds SDK is installed via composer, they are in vendor/microsoft/bingads/samples/V12/ReportRequests.php
BingAdController.php
namespace App\Http\Controllers;
use SoapVar;
use SoapFault;
use Exception;
use SoapClient;
use Illuminate\Http\Request;
use App\BingAd;
use App\Http\Controllers\Controller;
use Microsoft\BingAds\V12\Reporting\ReportRequestStatusType;
use Microsoft\BingAds\Auth\ServiceClient;
use Microsoft\BingAds\Auth\ServiceClientType;
use Microsoft\BingAds\Samples\V12\AuthHelper;
use Microsoft\BingAds\Samples\V12\ReportRequestLibrary;
include("/Applications/MAMP/htdocs/laravel/vendor/microsoft/bingads/samples/V12/ReportRequests.php");
class BingAdController extends Controller {
public function bingadsReporting(){
ReportRequests.php
namespace Microsoft\BingAds\Samples\V12;
// require_once __DIR__ . "/vendor/autoload.php";
require_once "/Applications/MAMP/htdocs/laravel/vendor/autoload.php";
include __DIR__ . "/AuthHelper.php";
include __DIR__ . "/ReportRequestLibrary.php";
use SoapVar;
use SoapFault;
use Exception;
use Microsoft\BingAds\V12\Reporting\ReportRequestStatusType;
use Microsoft\BingAds\Auth\ServiceClient;
use Microsoft\BingAds\Auth\ServiceClientType;
use Microsoft\BingAds\Samples\V12\AuthHelper;
use Microsoft\BingAds\Samples\V12\ReportRequestLibrary;
$GLOBALS['AuthorizationData'] = null;
$GLOBALS['Proxy'] = null;
$GLOBALS['CampaignManagementProxy'] = null;
class ReportRequests {
public $DownloadPath, $length, $folder;
Laravel keep saying the class not found...
I have been stuck in this problem for 2 days... please help
You shouldn't be manually calling include or require_once in your code - Laravel uses Composer's autoloader out of the box, so you should just be able to refer to the classes you need and it will do the rest.
First, ensure that you have installed Bing's SDK through Composer - i.e. it's added in your composer.json and it was installed through the command line tool. If you just downloaded it yourself and dropped it in the vendor directory it's not going to work.
Then you should be able to call new Microsoft\BindAds\Auth\ServiceClient or whichever class you want - Composer will know where and how to find this class for you.
If you have installed it through Composer and are still having issues you'll need to provide the exact code you're having issues with as well as the full error and stacktrace you're seeing so that we can assist debugging it.
Finally I found the solution.
Add "vendor/microsoft/bingads" into vendor/composer.json -> classmap
Don't know why BingAds didn't auto update composer.json even via composer install.
I'm on Laravel 5, I'm trying to integrate SAML 2.0 with it. I've found this package = https://github.com/aacotroneo/laravel-saml2
I tried follow their steps, but at the end when I use
<?php
namespace App\Http\Controllers;
class SAMLController extends Controller {
public function adminSignIn(){
return Saml2::login(URL::full());
}
}
I've already added
provider
'Aacotroneo\Saml2\Saml2ServiceProvider',
aliases
'Saml2' => 'Aacotroneo\Saml2\Facades\Saml2Auth',
Why do I still get this error?
Class 'App\Http\Controllers\Saml2' not found
Note : I've even retry after sudo composer dumpauto, same result.
You need to use full namespace for the facade:
\Saml2::login(URL::full());
Or add this to the top of the class:
use Saml2;
you need to explicitly write "use" on top
use Saml2;
This might work.
I'm trying to install and run the Facebook SDK on CodeIgniter using Composer.
CodeIgniter is installed and working nicely.
Composer support was added by doing the following:
curl -s http://getcomposer.org/installer | php
touch composer.json
Added the require lines to the composer.json file ("facebook/php-sdk-v4" : "4.0.*")
Ran composer update
All went to plan. Composer created a /vendor folder, and the Facebook SDK is there.
I then added Composer support to CodeIgniter by adding the line include_once './vendor/autoload.php'; to the top of index.php.
No errors at this point.
I'm now looking to call the SDK. I don't seem to be able to use any of the Facebook classes though. See below for things tried and failed...
var_dump(class_exists('Facebook')); shows bool(false)
FacebookSession::setDefaultApplication('app id removed', 'app secret removed');
Spits out:
Fatal error: Class 'FacebookSession' not found in /var/sites/***/public_html/application/controllers/welcome.php on line 13
And a more full example:
<?php
class Welcome extends CI_Controller {
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
public function index()
{
FacebookSession::setDefaultApplication('app id removed', 'app secret removed');
}
}
Spits out:
Fatal error: Welcome cannot use Facebook\FacebookSession - it is not a trait in /var/sites/***/public_html/application/controllers/welcome.php on line 5
You've mixed the position of the USE statement.
What you might do is to declare the classes from the FB SDK outside and before class, and not inside. By using Use inside a class you are pointing to trait functionality, which should be included into the class.
<?php
class MyClass extends MyBaseClass {
// this is a namespaced trait inside the class
// = extend class with trait
use SomeWhere\Trait;
}
?>
--
<?php
// this is the declaration of a namespaced class outside of the class
use SomeWhere\Class;
class MyClass extends MyBaseClass
{
public function helloWorld()
{
$c = new Class;
// ...
}
}
?>
--
Your code becomes:
<?php
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
class Welcome extends CI_Controller {
public function index()
{
FacebookSession::setDefaultApplication('app id removed', 'app secret removed');
}
}