Istiaque Ahmed
Istiaque Ahmed

Reputation: 6498

Cannot use Neo4j with Laravel with the help of NeoEloquent

I am trying to use Neo4j database in a Laravel project using NeoEloquent driver. I followed the instructions there. The config/database.php file has:

'default' => 'neo4j',

    'connections' => [

        'neo4j' => [
        'driver' => 'neo4j',
        'host'   => 'localhost',
        'port'   => 7687,
        'username' => 'neo4j',
        'password' => 'neo4j',
    ],
      .........
]

In web.php, I have:

Route::get('/save/country', [CountryController::class,'store'])->name('save_country');

Country.php model file has:

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use NeoEloquent;

// class Country extends Model
class Country extends NeoEloquent 
{
    use HasFactory;

    protected $fillable = [
      'country'
    ];


   
}

In CountryController.php, I have -

public function store(StoreCountryRequest $request) {

$country_info = new Country();
$country_info->country='India';
$relation = $country_info->save();

echo 'Success';

}

When I hit the URL save/country, I get the Exception:

RuntimeException Cannot connect to any server on alias: default with Uris: ('bolt://localhost:7687')

What is the thing that I am doing wrong ? How to make the problem go away ?

EDIT: I am using Neo4j Desktop app from here.

Upvotes: 0

Views: 425

Answers (1)

Sanjoy K. Paul
Sanjoy K. Paul

Reputation: 1

You can use post and put to store and update data, get is only used when you pull data from a database.

Update your code Route::get('/save/country', [CountryController::class,'store'])->name('save_country');

to store Route::post('/save/country', [CountryController::class,'store'])->name('save_country'); and to update Route::put('/update/country', [CountryController::class,'update'])->name('update_country');

Regarding the Neo4j driver exception, though I am not an expert in Neo4j, you can check and try the following things:

  • What is your development environment?
  • Check if port 7687 is open and available or not.
  • If you are using or installing multiple Apache servers for development, then close or shut down the other Apache server.

Check this link to get more about Neo4j: https://www.graphable.ai/resource/bolt-localhost-7687/

Upvotes: 0

Related Questions