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
Related
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');
Struggling since multiple days to get Notification::assertSentTo() method working in my feature test of reset password emails in a Laravel 5.6 app, yet receiving ongoing failures with following code:
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Support\Facades\Notification;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class UserPasswordResetTest extends TestCase
{
public function test_submit_password_reset_request()
{
$user = factory("App\User")->create();
$this->followingRedirects()
->from(route('password.request'))
->post(route('password.email'), [ "email" => $user->email ]);
Notification::assertSentTo($user, ResetPassword::class);
}
}
I have tried several ideas including to use Illuminate\Support\Testing\Fakes\NotificationFake directly in the use list.
In any attempt the tests keep failing with
Error: Call to undefined method Illuminate\Notifications\Channels\MailChannel::assertSentTo()
Looking forward to any hints helping towards a succesful test.
Regards & take care!
It seems like you are missing a Notification::fake(); For the correct fake notification driver to be used.
Notification::fake();
$this->followingRedirects()
...
I'm trying to access the User model in a utility I built that will eventually send emails out, this is being triggered with by cron, and I'm using php artisan schedule:run to test it. Below is the utility I'm starting to build out, and currently when test it I am getting 'I was triggered'. This is being triggered by a registered console command. Thats all working.
<?php
namespace App\Utility;
use Log;
use Mail;
use App\User;
class ReferralProgramUtility
{
static public function test()
{
LOG::info("I was triggered");
}
}
However, when I change this to pull in the User model....
<?php
namespace App\Utility;
use Log;
use Mail;
use App\User;
class ReferralProgramUtility
{
static public function test()
{
$user = User::all();
LOG::info($user);
}
}
I get the following error....
Trying to get property of non-object in /var/www/html/appname/app/User.php:32
I'm using another utility that has a similar configuration and uses the User model and this work fine, the only difference is that this is on is being triggered by task scheduler. Not sure what is causing this, and I'm fairly new to Laravel so any tips or recommendation would be hugely appreciated. Thanks, in advance.
I was install Laravel Scout with next instruction, but I have a problem :(
1) Used command composer require laravel/scout
2) Added into providers section 'Laravel\Scout\ScoutServiceProvider::class,'
3) Used command php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
4) Added Extends
Laravel\Scout\Searchable
use Searchable;
5) Used command composer require algolia/algoliasearch-client-php
6) Model has code:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
use DB;
class Product extends Model
{
use Searchable;
protected $table = 'products';
public static function getProductsBySearch($search)
{
// Список найденных продуктов
$searchProducts = Product::search('Test')
->get()
->all();
return $searchProducts;
}
}
But Have error:
AlgoliaSearch requires an applicationID
What is Algolia? How will solve it's problem?
You need to configure it with your Algolia credentials. It is a third party service providing the full text search functionality.
From the docs:
When using the Algolia driver, you should configure your Algolia id and secret credentials in your config/scout.php configuration file.
You can also use algolia dedicated library for laravel.
Laravel-scout-extended
There is cool feature like php artisan scout:status to see your local DB / and Index in algolia.
If you need more information as an advice you should watch this video :
Scout-Extended
I hope it will help you.
I'm new to Laravel and what I want to accomplish:
One laravel installation for multiple sites
Have some functions shared amongst all my sites, for instance User handling, while other functionality will be unique to a specific site
I want to pretty much have a wide variety of different sites under one installation, so I then can build an admin view where I can manage all sites.
How would I go about doing this? I have a fresh Laravel 4.2 installation.
You can have a look at the package rbewley4/multi-app-laravel on Github. Another hint can be found at this answer on StackOverflow
1. Create ConfigServiceProvider in app\Providers folder and set code:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Request;
class ConfigServiceProvider extends ServiceProvider {
public function register() {
$template = $_SERVER["SERVER_NAME"];
$config = app('config');
$config->set('template', $template);
}
}
2. Create TemplateServiceProvider in app\Providers folder and set code:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\FileViewFinder;
use Illuminate\View\ViewServiceProvider;
class TemplateServiceProvider extends ViewServiceProvider {
public function registerViewFinder() {
$this->app->bind('view.finder', function ($app) {
$template = $app['config']['template'];
if(file_Exists(realpath(base_path('themes/'.$template.'/views')))){
$paths = [realpath(base_path('themes/'.$template.'/views'))];
}else{
$paths = $app['config']['view.paths'];
}
return new FileViewFinder($app['files'], $paths);
});
}
}
3. Set providers in config/app.php :
App\Providers\ConfigServiceProvider::class,
App\Providers\TemplateServiceProvider::class,
4. Create your template forders > themes/{your_domain_name}/views