I followed steps in this related question but this error appeared to me, Can you help please?
HttpException in HttpRequestEventSubscriber.php line 74: Error on
Connection "default" with message "cURL error 7: Failed to connect to
localhost port 7474: Connection refused (see
http://curl.haxx.se/libcurl/c/libcurl-errors.html)"
this is my .env code
`APP_ENV=local
APP_DEBUG=true
APP_KEY=ChTIcRHTSR35M6rP0jwmOmhMNLuFpMVe
NEO4J_HOST=localhost
NEO4J_PORT=7474
NEO4J_USER=neo4j
NEO4J_PASSWORD=admin
NEO4J_TIMEOUT=300
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
`
this is NeoClientServiceProvider code
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Neoxygen\NeoClient\ClientBuilder;
class NeoClientServiceProvider extends ServiceProvider
{
/**
* Register the application services.
*
* #return void
*/
public function register()
{
$this->app->singleton('neoclient', function ($app) {
return ClientBuilder::create()
->addConnection('default', 'http', env('NEO4J_HOST'), intval(env('NEO4J_PORT')), true, env('NEO4J_USER'), env('NEO4J_PASSWORD'))
->setDefaultTimeout( intval(env('NEO4J_TIMEOUT')) )
->setAutoFormatResponse(true)
->build();
});
}
}
this is provider
App\Providers\NeoClientServiceProvider::class,
aliases
'NeoClient' => App\NeoClient::class
this is NeoClient class code
<?php namespace App;
use Illuminate\Support\Facades\Facade;
class NeoClient extends Facade
{
protected static function getFacadeAccessor() { return 'neoclient'; }
}
my test controller
<?php
namespace App\Http\Controllers;
use App\NeoClient;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class test extends Controller
{
public function index()
{
$data = NeoClient::sendCypherQuery('CREATE (user:User {name:"Kenneth"}) RETURN user');
}
}
when I made dump for this in function addConnection which is in ClientBuilder class
public function addConnection($alias, $scheme, $host, $port, $authMode = false, $authUser = null, $authPassword = null)
{
$this->configuration['connections'][$alias] = array(
'scheme' => $scheme,
'host' => $host,
'port' => $port,
'auth' => $authMode,
'user' => $authUser,
'password' => $authPassword,
);
dd($this);
return $this;
}
Ok. I installed Homestead to reproduce your environment. As told in the comments this should have been a host issue. I managed to make your connection to neo4j working :
ssh to homestead :
ssh vagrant#127.0.0.1 -p 2222
display the gateway ip of the vagrant box :
vagrant#homestead:~$ ip route show
default via 10.0.2.2 dev eth0
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15
192.168.10.0/24 dev eth1 proto kernel scope link src 192.168.10.10
Here the host gateway is 10.0.2.2
Use the gateway as neo4j host :
$ curl --user neo4j:admin "http://10.0.2.2:7474/db/data/"
"extensions" : { },
"node" : "http://10.0.2.2:7474/db/data/node",
"node_index" : "http://10.0.2.2:7474/db/data/index/node",
"relationship_index" : "http://10.0.2.2:7474/db/data/index/relationship",
"extensions_info" : "http://10.0.2.2:7474/db/data/ext",
"relationship_types" : "http://10.0.2.2:7474/db/data/relationship/types",
"batch" : "http://10.0.2.2:7474/db/data/batch",
"cypher" : "http://10.0.2.2:7474/db/data/cypher",
"indexes" : "http://10.0.2.2:7474/db/data/schema/index",
"constraints" : "http://10.0.2.2:7474/db/data/schema/constraint",
"transaction" : "http://10.0.2.2:7474/db/data/transaction",
"node_labels" : "http://10.0.2.2:7474/db/data/labels",
"neo4j_version" : "3.0.0-alpha.163"
Related
I am creating realtime chat app.
I have set up pusher in my laravel and vue.js project.
But it doesn't work. Though I don't have any error in the console.
Also, I have no error in network tab.
I need to create messenger app, so I need a realtime chat function.
Now, I can push user's comment but in the other user's window, nothing shows up.
But it does, once I refresh the page. I think my pusher setting has something wrong, because in the pusher debug console, any session is not executed.
Here is my code.
.env
BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
PUSHER_APP_ID=my id
PUSHER_APP_KEY=my app key
PUSHER_APP_SECRET= my secret key
PUSHER_APP_CLUSTER=mt1
broadcasting.php
'pusher' => [
'driver' => 'pusher',
'key' => env('my key'),
'secret' => env('my secret key'),
'app_id' => env('my id'),
'options' => [
'cluster' => 'ap3',
'encrypted' => true,
],
BroadcastServiceProvider.php
Broadcast::routes(['middleware' => ['auth:api']]);
require base_path('routes/channels.php');
bootstrap.js
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'my key',
cluster: 'ap3',
encrypted: true
});
NewMessage.php
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class NewMessage implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
/**
* Create a new event instance.
*
* #return void
*/
public function __construct(Message $message)
{
$this->message = $message;
}
/**
* Get the channels the event should broadcast on.
*
* #return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('messages.' . $this->message->to);
}
public function broadcastWith()
{
$this->message->load('fromContact');
return ["message" => $this->message];
}
}
routes/channel.php
use Illuminate\Support\Facades\Broadcast;
ContactsController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use App\Message;
class ContactsController extends Controller
{
public function get() {
$contacts = User::where('id', '!=', auth()->id())->get();//全部のcontactをjson経由でgetする
return response()->json($contacts);
}
public function getMessagesFor($id) {
$messages = Message::where('from', $id)->orWhere('to', $id)->get();
return response() -> json($messages);
}
public function send(Request $request) {
$message = Message::create([
'from' => auth()->id(),
'to' => $request->contact_id,
'text' => $request->text
]);
return response()->json($message);
}
}
Here is what I tried.
run all the command according to the laravel document.
php artisan chache:clear
and run the server again.
run php artisan queue:work
in command terminal
Did you write
window.Echo.private('channelName').listen('EventName',function(e){
})
in your application to listen
In your send() function you should write
broadcast(new NewMessage($message));
to broadcast the message.
I want to create a test which I will use from Controller so I write:
<?php
namespace App\Http\Controllers\Modules;
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Laravel\Dusk\ElementResolver;
use Exception;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Laravel\Dusk\Browser;
use Laravel\Dusk\Chrome\ChromeProcess;
class TestController extends Controller {
public function test() {
$process = (new ChromeProcess)->toProcess();
if ($process->isStarted()) {
$process->stop();
}
$process->start();
$options = (new ChromeOptions)->addArguments(['--disable-gpu', '--headless', '--no-sandbox']);
$capabilities = DesiredCapabilities::chrome()
->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = retry(1, function () use ($capabilities) {
return RemoteWebDriver::create('http://localhost:9515', $capabilities, 60000, 60000);
}, 50);
$browser = new Browser($driver, new ElementResolver($driver, ''));
$browser->resize(1920, 1080);
$browser->visit('https://example.com/login')->click('#.btn > form > div.auth-form-body.mt-3 > input.btn.btn-primary.btn-block');
$browser->driver->takeScreenshot(base_path('tests/Browser/screenshots/logged.png'));
}
}
When I run this script using localhost:8000/test I got this message:
Facebook \ WebDriver \ Exception \ WebDriverCurlException Curl error
thrown for http POST to /session with params:
{"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"","args":["--disable-gpu","--headless","--no-sandbox"]}}}
Failed to connect to localhost port 9515: Connection refused
How I can solve this problem?
Current I use WAMP server on Win10 for local testing but then I will move the code on Linux Ubuntu 18.
I can't fully explain it, but this works for me on Windows:
$process = (new ChromeProcess)->toProcess();
if ($process->isStarted()) {
$process->stop();
}
$process->start(null, [
'SystemRoot' => 'C:\\WINDOWS',
'TEMP' => 'C:\Users\<User>\AppData\Local\Temp',
]);
[...]
Replace <User> with the name of your user directory.
Symfony 4 app with Braintree JS drop-in UI
I have created a service called Braintree to start testing.
namespace App\Services;
use Braintree\ClientToken;
class Braintree
{
// environment variables:
const ENVIRONMENT = 'BRAINTREE_ENVIRONMENT';
const MERCHANT_ID = 'BRAINTREE_MERCHANT_ID';
const PUBLIC_KEY = 'BRAINTREE_PUBLIC_KEY';
const PRIVATE_KEY = 'BRAINTREE_PRIVATE_KEY';
/** #var \Braintree_Gateway */
private $gateway;
function __construct() {
$gateway = new \Braintree_Gateway([
'environment' => getenv(self::ENVIRONMENT),
'merchantId' => getenv(self::MERCHANT_ID),
'publicKey' => getenv(self::PUBLIC_KEY),
'privateKey' => getenv(self::PRIVATE_KEY)
]);
}
public function generate() {
return ClientToken::generate();
}
I am getting the following error:
HTTP 500 Internal Server Error
Braintree\Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree\Gateway).
The BT config has been properly entered into the .env file. Why is it not setting the MERCHANT_ID?
Edit:
Add config
Braintree_Gateway:
class: Braintree_Gateway
arguments:
-
'environment': '%env(BRAINTREE_ENVIRONMENT)%'
'merchantId': '%env(BRAINTREE_MERCHANT_ID)%'
'publicKey': '%env(BRAINTREE_PUBLIC_KEY)%'
'privateKey': '%env(BRAINTREE_PRIVATE_KEY)%'
Edit 2:
The stack trace:
Braintree\Exception\
Configuration
in vendor\braintree\braintree_php\lib\Braintree\Configuration.php (line 261)
public function assertHasAccessTokenOrKeys() { if (empty($this->_accessToken)) { if (empty($this->_merchantId)) { throw new Exception\Configuration('Braintree\\Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree\\Gateway).'); } else if (empty($this->_environment)) { throw new Exception\Configuration('Braintree\\Configuration::environment needs to be set.'); } else if (empty($this->_publicKey)) { throw new Exception\Configuration('Braintree\\Configuration::publicKey needs to be set.'); } else if (empty($this->_privateKey)) {
Configuration->assertHasAccessTokenOrKeys()
in vendor\braintree\braintree_php\lib\Braintree\ClientTokenGateway.php (line 34)
ClientTokenGateway->__construct(object(Gateway))
in vendor\braintree\braintree_php\lib\Braintree\Gateway.php (line 59)
Gateway->clientToken()
in vendor\braintree\braintree_php\lib\Braintree\ClientToken.php (line 18)
ClientToken::generate()
in src\Services\Braintree.php (line 25)
Braintree->generate()
in src\Controller\ProfileController.php (line 50)
ProfileController->booking_new(object(EntityManager), object(Request), object(Braintree))
in vendor\symfony\http-kernel\HttpKernel.php (line 149)
Edit 3:
namespace App\Services;
use Braintree_Gateway;
class Braintree extends Braintree_Gateway
{
//Configure Braintree Environment
public function __construct(Braintree_Gateway $gateway)
{
$this->$gateway = new Braintree_Gateway([
'environment' => 'sandbox',
'merchantId' => 'n5z3tjxh8zd6272k',
'publicKey' => 'v4rjdzqk3gykw4kv',
'privateKey' => '4ab8b962e81ee8c43bf6fa837cecfb97'
]);
}
//Generate a client token
public function generate() {
return $clientToken = $this->clientToken()->generate();
}
}
Error is now:
Catchable Fatal Error: Object of class Braintree\Gateway could not be converted to string
Am I getting closer to generating the client token??
The .env-file does not actually populate the system environment. Instead it works as a fallback when the environment is not set. Your call to getenv() only takes into account the system environment. For your file to take effect you have to use the Service container.
#config/services.yaml
services:
_defaults:
autowire: true
autoconfigure: true
#... all the existing services
Braintree_Gateway:
class: Braintree_Gateway
arguments:
-
'environment': '%env(BRAINTREE_ENVIRONMENT)%'
'merchantId': '%env(BRAINTREE_MERCHANT_ID)%'
'publicKey': '%env(BRAINTREE_PUBLIC_KEY)%'
'privateKey': '%env(BRAINTREE_PRIVATE_KEY)%'
The special parameter %env()% will check your system environment for the variable first and if that is not set it will go through the .env files to see if there is a fallback defined. You can also read up on this in the docs: https://symfony.com/doc/current/configuration/external_parameters.html#environment-variables
This will give the service Braintree_Gateway, that you built manually inside your service. Just like with any other service you can inject it into your service instead and autowiring will pass in an already generated Braintree Gateway:
namespace App\Services;
use Braintree\ClientToken;
class Braintree
{
private $gateway;
public function __construct(\Braintree_Gateway $gateway)
{
$this->gateway = $gateway;
}
# ... methods using the gateway
}
I wrote tests with Laravel Dusk and no need to clear previous tests data in database, so everything was OK.
My problem starts when add use DatabaseMigrations; in DuskTestCase.php file to make sure all previous tests data is purged.
But the problem is the loginAs not working. so lots of my tests is fail, because my tests are redirected to application login page!
Any help will be appreciated.
This is my test code:
<?php
namespace Tests\Browser;
use App\Models\Brand;
use App\Models\User;
use Laravel\Dusk\Browser;
use Tests\Browser\Components\DashboardCategoryForm;
use Tests\DuskTestCase;
class DashboardBrandsTest extends DuskTestCase
{
/**
* A Dusk test example.
*
* #return void
* #throws \Exception
* #throws \Throwable
*/
public function testBrandList()
{
$user = factory(User::class)->create();
$this->browse(function (Browser $browser) use ($user) {
$browser->loginAs($user)
->visitRoute('dashboard.brands.index')
->assertSee('Brands')
->assertSee('id')
->assertSee('name')
->assertSee('image')
->assertSee('updated_at')
->assertSee('operations');
});
}
/**
* #throws \Exception
* #throws \Throwable
*/
public function testCreateUpdateDeleteBrand()
{
$user = factory(User::class)->create();
$this->browse(function (Browser $browser) use ($user) {
$expectedName = 'Brand ' . $user->id;
$expectedNameEdited = $expectedName . ' Edited';
$expectedShortDesc = 'This is a little desc for test.';
$expectedShortDescEdited = 'Edited desc';
$expectedImage = __DIR__ . '/photos/test.jpg';
$browser->loginAs($user)
->visitRoute('dashboard.brands.index')
->click('#new-category')
->assertRouteIs('dashboard.brands.create')
->within(new DashboardCategoryForm, function ($browser)
use ($expectedName, $expectedShortDesc, $expectedImage) {
$browser->fillCategory(
$expectedName,
$expectedShortDesc,
$expectedImage
);
})
->click('#submit')
->assertRouteIs('dashboard.brands.index')
->assertSee($expectedName);
$latestRecord = Brand::orderBy('updated_at', 'desc')->first();
$browser
->click('#edit-category' . $latestRecord->id)
->within(new DashboardCategoryForm, function ($browser)
use ($expectedName, $expectedShortDesc) {
$browser->checkCategory(
$expectedName,
$expectedShortDesc
);
})
->within(new DashboardCategoryForm, function ($browser)
use ($expectedNameEdited, $expectedShortDescEdited, $expectedImage) {
$browser->fillCategory(
$expectedNameEdited,
$expectedShortDescEdited,
$expectedImage
);
})
->click('#submit')
->assertRouteIs('dashboard.brands.index')
->assertSee($expectedNameEdited)
->click('#edit-category' . $latestRecord->id)
->within(new DashboardCategoryForm, function ($browser)
use ($expectedNameEdited, $expectedShortDescEdited) {
$browser->checkCategory(
$expectedNameEdited,
$expectedShortDescEdited
);
})
->click('#submit')
->assertRouteIs('dashboard.brands.index')
->click('#delete-category' . $latestRecord->id)
->acceptDialog()
->pause(500)
->assertDontSee($expectedNameEdited);
});
}
}
This is my env.dusk.local:
APP_NAME=Laravel
APP_ENV=testing
APP_KEY=base64:EOMuHiEoMcS0YvJQq+b/bSVm0kXfJwNnNFJ7WOQwWwQ=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://site.local
DB_CONNECTION=mysql
DB_HOST=10.5.0.7
DB_PORT=3306
DB_DATABASE=db_test
DB_USERNAME=root
DB_PASSWORD=secret
BROADCAST_DRIVER=log
CACHE_DRIVER=database
SESSION_DRIVER=database
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
REDIS_HOST=10.5.0.9
REDIS_PASSWORD=secret
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
As you're starting off by editing a category, that implies that you're expecting there to already be data in your database. DatabaseMigrations creates your database structure, but it doesn't seed your database, so if you're trying to login there may not be a user in your database for you to loginAs.
I found that the best way to resolve this is to add seeding at the start of each test, though this does make them pretty slow. I tried a number of ways and this was the only one I could get to work.
public function setUp()
{
parent::setUp();
$this->artisan('db:seed');
}
I am newbie in elasticsearch and somewhere in laravel also.. I am trying to configure elasticsearch with laravel . elasticsearch is running on 9200 port. When execute below code , it throws cURL error.I never configured 1080 port. Don't knw why it's trying to connect 1080 port ? How to change this port ?
code
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Elasticsearch\ClientBuilder;
use Elastica\Client as ElasticaClient;
class clientController extends Controller
{
protected $elasticsearch;
protected $elastica;
public function __construct()
{
$logger = ClientBuilder::defaultLogger('d:/your.log');
$this->elasticsearch = ClientBuilder::create()
->setLogger($logger)
->setRetries(0)
->build();
$elasticConfig=['host'=>"locahost",
"port"=>9200,
"index"=>'pets'];
$this->elastica = new ElasticaClient($elasticConfig);
}
public function elasticsearchTest(){
dump($this->elasticsearch);
// echo "\n\n Retrive Doc";
$param = [
'index' => 'pets',
'type' => 'dog',
'id'=>'1'
];
$res = $this->elasticsearch->get($param);
dump($res); exit;
}
}