How to use Binance api in laravel with Controller - laravel

I can't use binance api in laravel
I installed Php binance api from composer require "composer require jaggedsoft/php-binance-api" from "https://github.com/jaggedsoft/php-binance-api" 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\Binance;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* #return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$api = new Binance\API();
$key = "----";
$secret = "---";
$api = new Binance\API($key, $secret);
$data = $api->price("BNBBTC");
return view('home', $data);
}
}
When I runned the route I got this error:
Error
Class 'App\Http\Controllers\Binance\API' not found
http://127.0.0.1:8000/home

Either import the Binance on top of your file or use backslash \

Related

Mail Not working in laravel console command within handle function

I'm developing a new Laravel application. When I'm using mail to send messages via laravel schedule command, I'm getting the following error:
Swift_TransportException with message 'Process could not be started
[The system cannot find the path specified. ]
This is my Command file.
EmailReminder.php
<?php
namespace App\Console\Commands;
use App\ScheduleMeeting;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use Modules\User\Emails\MentorEmailReminder;
class EmailReminder extends Command
{
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'reminder:emails';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Send email notification to user about reminders.';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* #return int
*/
public function handle()
{
$date = now()->tz('Asia/Singapore')->addDay(); // Current date is added one day
$newDate = $date->format('Y-m-d g:i A');
$tomorrow_meetings = ScheduleMeeting::where('start_time','=', $newDate)
->where('status',1)
->where('meeting_type',0)
->get();
$data = [];
foreach($tomorrow_meetings as $meeting){
$data[$meeting->mentor_id][] = $meeting->toArray();
}
foreach($data as $mentorId => $reminders){
$this->sendEmailToUser($mentorId, $reminders);
}
}
private function sendEmailToUser($mentorId, $reminders){
$user = \App\User::find($mentorId);
Mail::to($user)->send(new MentorEmailReminder($reminders));
}
}
This is my email file.
MentorEmailReminder.php
<?php
namespace Modules\User\Emails;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class MentorEmailReminder extends Mailable
{
use Queueable, SerializesModels;
public $reminders;
public function __construct($reminders)
{
$this->reminders = $reminders;
}
public function build()
{
$subject = 'Reminder: Mentoring Session with';
return $this->from(setting_item("email_from_address"), 'Uplyrn')->subject($subject)->view('User::emails.mentor-email-reminder')->with([
'reminders' => $this->reminders,
]);
}
}
This is .env file.
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

Getting an array_merge error on account verified event using Laravel 8 and Pusher

I am using Pusher 5 running on Laravel 8, I was trying to broadcast user verified event. However, when I verify my account I get the following error:
Pusher error
My listener code is as follows:
<?php
namespace Illuminate\Auth\Events;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Broadcasting\Channel;
class Verified implements ShouldBroadcast
{
use SerializesModels;
public $afterCommit = true;
/**
* The verified user.
*
* #var \Illuminate\Contracts\Auth\MustVerifyEmail
*/
public $user;
/**
* Create a new event instance.
*
* #param \Illuminate\Contracts\Auth\MustVerifyEmail $user
* #return void
*/
public function __construct($user)
{
$this->user = $user;
}
public function broadcastOn()
{
return new Channel('users');
}
public function broadcastAs()
{
return 'account-verified';
}
public function broadcastWith()
{
return ['id' => 'heya'];
}
}
Any help would be highly appreciated!
try composer require pusher/pusher-php-server ^4.1,
at least this works with the beyondecode/laravel-websockets,
not sure about the official pusher server

Problems creating a ComposerServiceProvider in Laravel 5.4

Im working on a Laravel 5 app and im trying to set up a ComposerServiceProvider to pass data to a couple of views (im trying now to add it to the layout/app.blade.php).
I did this following the documentation but the data im trying to add is still undefined..
In my config/app.php I added to the providers:
App\Providers\ComposerServiceProvider::class,
On ComposerServiceProvider.php
boot method:
View::composer(['layouts.app'], 'App\ViewComposers\LayoutAppComposer');
On the new created LayoutAppComposer.php
compose(View $view) method:
$metaTitle = 'MetaTitle';
$view->with('metaTitle', $metaTitle)
But When i access the url I still get:
Undefined variable: metaTitle (View: .../resources/views/layouts/app.blade.php)
Am I missing something here??
ServiceProvider
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
class ComposerServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* #return void
*/
public function boot()
{
View::composer(['layouts.app'], 'App\ViewComposers\LayoutAppComposer');
}
/**
* Register the application services.
*
* #return void
*/
public function register()
{
}
}
LayoutAppComposer
<?php
namespace App\ViewComposers;
use Illuminate\Support\Facades\Session;
use Illuminate\View\View;
class LayoutAppComposer {
protected $metaTitle;
public function __construct($metaTitle)
{
$this->metaTitle = $metaTitle;
}
/**
* Bind data to the view.
*
* #param View $view
* #return void
*/
public function compose(View $view) {
$this->metaTitle = 'MetaTitle';
$view->with('metaTitle', $this->metaTitle);
}
}
Try changing:
$metaTitle = 'MetaTitle';
$view->with('metaTitle', $metaTitle)
to
$this->metaTitle = 'metaTitle';
$view->with('metaTitle', $this->metaTitle)
setup $this->metaTitle as a protected class member and assign it in the composer constructor. it may be that $metaTitle is getting garbage collected before you use it since this being resolved at the service provider level.
Since you're registering the composer with your app layout, instead you may need to use the wildcard character in place of app.layout like such:
View::composer('*', function ($view) {
//
});
To resolve $metaTile for the View Composer, try binding in your AppServiceProvider:
$this->app->bind('metaTitle', 'the string i want displayed across all views');

Laravel pass object to view

When I'm trying to pass an object through a view with the AppServiceProvider it gives an error an says
Trying to get property of non-object
This is currently my App\Providers:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\User;
use Auth;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
$users = Auth::user();
view()->share('user','users');
}
/**
* Register any application services.
*
* #return void
*/
public function register()
{
//
}
}
And when I say in the view:
{!! user->name !!}
It throws an error.
you are missing the '$' on users when passing the variable to view. So it can't be rendered on the view.
it must be:
$users = Auth::user();
view()->share('user', $users);

Laravel 5 Command and Handler issue

I am working one of my project with laravel 5. During the implementation i got struct with one issue which is related to command and handler.
I used artisan command to generate command
php artisan make:command TestCommand --handler
I generated command at app/commands folder "TestCommand.php"
<?php
namespace App\Commands;
use App\Commands\Command;
class TestCommand extends Command
{
public $id;
public $name;
public function __construct($id, $name)
{
$this->id = $id;
$this->name = $name;
}
}
Also my TestCommandHandler.php looks like this
<?php
namespace App\Handlers\Commands;
use App\Commands\TestCommand;
use Illuminate\Queue\InteractsWithQueue;
class TestCommandHandler
{
/**
* Create the command handler.
*
* #return void
*/
public function __construct()
{
//
}
/**
* Handle the command.
*
* #param TestCommand $command
* #return void
*/
public function handle(TestCommand $command)
{
dd($command);
}
}
Whenever dispatch this command from controller it shows following issue
InvalidArgumentException in Dispatcher.php line 335:
No handler registered for command [App\Commands\TestCommand]
Please, Anybody help me to solve this problem. Thank you
By default Laravel 5.1.x does not included BusServiceProvider. So we should create BusServiceProvider.php under provider folder and include that in to config/app.php.
BusServiceProvider.php
<?php namespace App\Providers;
use Illuminate\Bus\Dispatcher;
use Illuminate\Support\ServiceProvider;
class BusServiceProvider extends ServiceProvider {
/**
* Bootstrap any application services.
*
* #param \Illuminate\Bus\Dispatcher $dispatcher
* #return void
*/
public function boot(Dispatcher $dispatcher)
{
$dispatcher->mapUsing(function($command)
{
return Dispatcher::simpleMapping(
$command, 'App\Commands', 'App\Handlers\Commands'
);
});
}
/**
* Register any application services.
*
* #return void
*/
public function register()
{
//
}
}
config/app.php
'providers' => [
App\Providers\BusServiceProvider::class
]
So it may help others. Thank you

Resources