Class 'Dropbox\Client' not found ( Laravel ) - laravel

I'm use Dropbox image hosting, I downloaded Dropbox's install league / flysystem-dropbox package, but when I ran the code below it crashed
Class 'Dropbox \ Client' not found.
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Dropbox\Client;
use Dropbox\WriteMode;
class ExpenseController extends Controller
{
public function postExpenseAdd( Request $request ){
$Client = new Client(env('DROPBOX_TOKEN'), env('DROPBOX_SECRET'));
$file = fopen(public_path('img/admin.png'), 'rb');
$size = filesize(public_path('img/admin.png'));
$dropboxFileName = '/myphoto4.png';
$Client->uploadFile($dropboxFileName,WriteMode::add(),$file, $size);
$links['share'] = $Client->createShareableLink($dropboxFileName);
$links['view'] = $Client->createTemporaryDirectLink($dropboxFileName);
print_r($links);die;
}
}

This will not be an answer to your current question (at least not with the package you are currently working with), but this might get you back on the right track:
The league/flysystem-dropbox won't work anymore as this package uses the API v1 version of dropbox that has meanwhile been deprecated (API v1 will be completely unavailable on September 28, 2017).
Since the package is not maintaned anymore and will not receive an update to the API v2 version you should take a look at the srmklive/flysystem-dropbox-v2 package.
In short: you can run composer require srmklive/flysystem-dropbox-v2 to get started with the new version of the API.

Related

Kreait\Firebase\Exception\Database\DatabaseError 404 Not Found

I am new to Laravel so i have been trying to connect Laravel to a Firebase Realtime database but i am getting this error Kreait\Firebase\Exception\Database\DatabaseError
404 Not Found . I have the Service account in the controllers directory and properly referenced in the Firebase controller.
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Kreait\Firebase;
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
use Kreait\Firebase\Database;
class FirebaseController extends Controller
{
$factory = (new Factory)->withServiceAccount(__DIR__.'/myServiceAccount.json');
$database = $factory->createDatabase();
$newPost = $database->getReference('myrealtime-default-rtdb/blog/posts')->push(['title' => 'Post title','body' => 'This should probably be longer.']);
echo"<pre>";
print_r($newPost->getvalue());
}
}
}
Using the new Factory pattern won't work (it's already handled by the Laravel Service Provider).
Personally I'd recommend using the app() helper. It's quite easy but before that make sure you've followed the installation process in the documentation. You might've missed something
Here's a link to that: https://github.com/kreait/laravel-firebase
Also make sure you include both the path to your Service Account json file and the database URL for your project in your .env file (I prefer using this method personally)
So in your .env file you should have something like
FIREBASE_CREDENTIALS = path_to_your_service_account_file.json
FIREBASE_DATABASE_URL= https://your-project-url.firebaseio.com/
(you can find this url when you open RealTime databases in your firebase console)
If you don't use auto-discovery make sure to add Kreait\Laravel\Firebase\ServiceProvider::class to your providers in the config/app.php file
run a vendor publish
Then in your controller you could have something like this
namespace App\Http\Controllers;
class FirebaseController extends Controller {
//
protected $database;
public function __construct()
{
$this->database = app('firebase.database');
}
public function index(){
$new_post = $this->database->getReference('your-reference')>push(["title" =>"something"]);
} }
Remember: on Linux, place Firebase config files etc. in a folder that user 'apache' can read! So, for example, do not place such files in /home/myname/firebase.json. Even if you do chmod 777 firebase.json, this file may not be accessible by user 'apache', hence the 404.
Then you do not need to use env variables.
$factory = (new Factory())->withServiceAccount(DIR.'/vendor/firebase-adminsdk.json');

Connection Firebase Firestore to laravel

I have installed laravel 5.8 and firebase project with firestore database.
"name": "laravel/framework",
"version": "v5.8.36",
Firestore database connected to android app. App fetches data good from Firestore. Than I want to create admin panel with laravel for android app and want to integrate laravel with that database.But can not do this.
What I did:
installed php7.2
installed laravel 5.8.*
added php extension gRPC*
Added gRPC as a Composer dependency composer require "grpc/grpc:^v1.1.0" in laravel project
installed composer require google/cloud-firestore
Generated Firebase Admin SDK json file and saved into storage folder in laravel
Added this variable GOOGLE_APPLICATION_CREDENTIALS=/storage/files/progressive-yooung-team-firebase-adminsdk-ax7wi-d2a85ecabc.json (json file which generated firebase admin SDK) in .env file of laravel
installed composer require kreait/firebase-php ^4.35
Created Controller 'VarController' code:
<?php
namespace App\Http\Controllers;
use Kreait\Firebase\Factory;
class VarController extends Controller
{
public function index()
{
print_r("Output: 1");
$factory = new Factory();
print_r("Output: 2");
$firestore = $factory->createFirestore();
print_r("Output: 3");
$database = $firestore->database();
$userRef = $database->collection('users');
$snapshot = $userRef->document('Hus')->snapshot();
if($snapshot->exists()) {
printf('Document data:' . PHP_EOL);
print_r($snapshot->data());
}
print_r("Output: 4");
}
}
Problem is, It does not fetch data from firestore document 'Hus' and its data exists:
users > Hus > name: "Husniddin"
I put print_r("Output: 1"), Output: 2, etc... in order to know where is problem. On screen I see only: Output: 1 Output: 2.
Also don't forget to import these .
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
use \Kreait\Firebase\Database;
use Google\Cloud\Firestore\FirestoreClient;
After that , call the ServiceAccount() inside your function.
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/Firebase.json');
$firebase = (new Factory)
->withServiceAccount($serviceAccount);
$firestore = new FirestoreClient([
'projectId' => 'Your project name',
]);
$collectionReference = $firestore->collection('users');
$documentReference = $collectionReference->document('Search element from document');
$snapshot = $documentReference->snapshot();
change
$snapshot = $userRef->document('Hus')->snapshot();
to
$snapshot = $userRef->document('Hus')->documents();

How can run Binance api in laravel with Controller

I can't use binance api in laravel
I installed Php binance api from composer require "jaggedsoft/php-binance-api #dev" but examples not working in laravel.I had some errors when I tried.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
require '../vendor/autoload.php';
class BinanceController extends Controller
{
public function list()
{
$api = new Binance\API();
$key = "----";
$secret = "---";
$api = new Binance\API($key, $secret);
$price = $api->price("BNBBTC");
return $price;
}
}
When I runned the route I got this error:
Symfony\Component\Debug\Exception\FatalThrowableError Class
'App\Http\Controllers\Binance\API' not found
You're not importing Binance\API correctly. Laravel believes the Binance\Api class is located in the App\Http\Controllers\Binance namespace. Which it is not.
Try $api = new \Binance\API();
Or put it in your use cases.
use Binance\API
I also found an old wrapper which you may be able to import if there hasn't been any changes to Binance since but I highly doubt it. Since your case is specific to Laravel, look for a Binance wrapper for Laravel specifically. Here may contain some useful information on how to use non-laravel packages, with laravel

Laravel Cashier Call to Undefined Method onGracePeriod()

So I recently upgraded from Laravel 5.1 -> 5.4 and Cashier from 5.0 -> 7.0. In my blade I am using this check to see if a user is in their grace period
<?php if(Auth::check() && Auth::user()->onGracePeriod()): ?>
However now this code throws an exception
Call to undefined method Illuminate\Database\Query\Builder::onGracePeriod()
As per the documentation my user model has the import
use Laravel\Cashier\Billable;
and the use statement inside of the class itself
class User extends Model implements AuthenticatableContract,
CanResetPasswordContract
{
use Authenticatable, CanResetPassword, Billable;
/**
* The database table used by the model.
*
* #var string
...
Is there anything else that could cause this error? Searching through the code it looks like the function is within the Subscription.php within cashier but I cannot seem to find a fix. I also have the included dates that is often referenced in the documentation
protected $dates = ['trial_ends_at', 'subscription_ends_at'];
But I had that and my DB using that before back on 5.1 so I doubt that is related. Any ideas? The only thing I can think of is that when moving from 5.1 -> 5.4 I had to remove the "BillableContract" since it appears that it is no longer being used, is there something I have to replace that with? Thanks!
I believe you have to reference their subscription piece directly - not directly off the user (I think it's being used wrong is what I'm saying);
Per the documentation you check for onGracePeriod like this:
if ($user->subscription('main')->onGracePeriod()) {
//
}

Is there a way to specify the installation location for composer? (PSR-4)

I'm using composer to install my package and I'm trying to install my bundle in a very specific location.
In short, I have my packages with the following namespace prefixes:
TeamXyz/AbcBundle
TeamXyz/AbcComponent
Now, since we have tons of components and bundles, we want to separate them into 2 folders like this:
vendor/TeamXyz/Component/AbcComponent
vendor/TeamXyz/Bundle/AbcBundle
It used to work very well but with PSR-4 I cannot seem to be able to control the location where my package should be installed. I wonder if I have to write custom package installer for composer to be able to do this?
Ok, I found out a way to do that, simply wrote my own custom package installer and voila.
<?php
/**
* Created by myTeam.
* Date: 6/11/14
* Time: 1:43 PM
* Question? Come to our website at http://my.com
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace My\PackageInstaller;
use Composer\Package\PackageInterface;
use Composer\Installer\LibraryInstaller;
class BundleInstaller extends LibraryInstaller
{
/**
* {#inheritDoc}
*/
public function getPackageBasePath(PackageInterface $package)
{
$prefix = substr($package->getPrettyName(), 0, 3);
if ('my/' !== $prefix) {
throw new \InvalidArgumentException(
'Unable to install package, my package '
. 'should always start their package name with '
. '"my/"'
);
}
$packageName = str_replace('my/', '', $package->getPrettyName());
return $this->vendorDir . '/my/Bundle/' . $packageName;
}
/**
* {#inheritDoc}
*/
public function supports($packageType)
{
return 'my-bundle' === $packageType;
}
}
And yes I understand everything you guys complain about, but a tool is a tool and one person can use it the best way that fits his need. At least that's what I believe :). Maybe I'm doing something stupid here for not using Composer the exact way it was meant to be used. But hey, if we are using all the tools the exact ways they were meant to be used, lots of innovation would have happened in the first place :)

Resources