Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Error: Undefined array key "host" - "mongodb/laravel-mongodb": "v4.0.0-ALPHA1" #2621

Closed
Elodiemllr opened this issue Sep 14, 2023 · 4 comments · Fixed by #2975
Closed

"Error: Undefined array key "host" - "mongodb/laravel-mongodb": "v4.0.0-ALPHA1" #2621

Elodiemllr opened this issue Sep 14, 2023 · 4 comments · Fixed by #2975

Comments

@Elodiemllr
Copy link

Elodiemllr commented Sep 14, 2023

  • Laravel-mongodb Version: "v4.0.0-ALPHA1"
  • PHP Version: "^8.1"
  • Database Driver & Version: php_mongodb-1.16.2-8.1-nts-x64

Description:

Steps to reproduce

  1. install Laravel-mongodb Version: "v4.0.0-ALPHA1
  2. Configure database.php with
'connections' => [

        'mongodb' => [
            'driver' => env('MONGO_DB_CONNECTION'),
            'dsn' => env('MONGO_DB_URI'),
            'database' => env('MONGO_DB_DATABASE'),
]]
  1. Create a model and try a post request
<?php

namespace App\Models;
use MongoDB\Laravel\Eloquent\Model;
class Test extends Model
{
    protected $connection = 'mongodb';

    protected $fillable = [
        'Test'
    ];
}

----------

<?php

namespace App\Http\Controllers;

use App\Models\Json;
use Illuminate\Http\Request;
class JsonController extends Controller
{
 public function postTestForm(Request $request)
    {
        try {
            $test = Test::create([
                'Test' => $request->get('test'),
              
            ]);
            $test->save();

            return 'success test has been successfully created';
        } catch (\Exception $e) {
            return 'Error: ' . $e->getMessage();
        }
    }
}

Expected behaviour

I should get a new object in my database.

Actual behaviour

First, I never had to specify a 'host' with laravel 9 and jenssegers/mongodb but now i got ' "Error: Undefined array key "host""'.
So i have tried to had a host in my database config.
Then, when I try another time to postTestForm with the host added I got a return 'success test has been successfully created' but nothing is created in my database.

I have tried with v4.0.0-ALPHA1 and v4.0.0-ALPHA2.
I don't have this problem with laravel 9 and jenssegers package.

@Elodiemllr
Copy link
Author

Was a mistake from me so not a problem but I can't delete the post. Thank you

@GromNaN
Copy link
Member

GromNaN commented Sep 14, 2023

Note that you can upgrade to 4.0.0-rc1.

Was a mistake from me so not a problem but I can't delete the post. Thank you

No worries. What was your mistake and the solution if someone else have this problem. Sometime we can improve error messages.

@andes2912
Copy link

Was a mistake from me so not a problem but I can't delete the post. Thank you

I have the same problem, can you explain this issue for me?

@GromNaN
Copy link
Member

GromNaN commented May 23, 2024

In your configuration, you must provide either dsn or host parameter. https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/fundamentals/connection/connect-to-mongodb/#connection-example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants