Tuesday, 15 March 2011

php - laravel mongodb does not save -



php - laravel mongodb does not save -

the documentation https://github.com/jenssegers/laravel-mongodb doesn't go much detail saving info mongodb.

i've installed fresh install of laravel , set mongo connections in docs, installed mongodb itself.

created model

use jenssegers\mongodb\model eloquent; class notifications extends eloquent { protected $connection = 'mongodb'; protected $collection = 'notifications'; public static function foo() { homecoming 'test returning model'; } }

and create simple route test

route::get('notifiction' , function(){ $notifiction = new notifications(); $arr = array('name' => 'john doe'); $notifiction->save($arr); });

but when run localhost/mongo/public/notifiction whoops, looks went wrong. i'm not sure else needs doing save info mongodb through laravel?

this error mass assignment. laravel treats every thing unsafe before saving database. have whitelist fields trying save.

the way in model. lets trying save info in "users table" using "user model". first open app/models/user.php , add together next line:

class user extends eloquent { protected $fillable = ['name'];

}

above, in fillable listing "name" want save name controller (if have additional info fill in array). can save info controller.

eg: user::create(array('name' => 'john')); save name in "users collection". please note name of collection wil name of model unless specified otherwise.

[if not solve problem, enable debug going app/config/app.php , seting debug =true. find error , seek searching.]

php mongodb laravel

No comments:

Post a Comment