1

I'm using the laravel-mongodb library ( https://github.com/jenssegers/laravel-mongodb )

When I want to create a new record, i get this error:

strlen() expects parameter 1 to be string, array given

in project.local/vendor/mongodb/mongodb/src/Collection.php:104

This is the Model: Category.php

namespace App\Models;

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class Category extends Eloquent
{
    protected $collection = [ 'categories' ];
    protected $fillable = [ 'name', 'parentId' ];
}

And this is my store method:

public function store(Request $request)
{
    // e1: Category::create([ 'name' => 'T-shirts' ]);
    $n = new Category;
    $n->name = 'T-shirts';
    $n->save();

    return back();
}

Error Printscreen

1 Answer 1

1

Change your $collection to string, you have set it as array which is why you are getting that error

$collection = 'categories';

Here is an example from that library github Readme

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class User extends Eloquent {

    protected $collection = 'users_collection';

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.