How to insert data into MongoDB with Laravel

laravel mongodb crud
laravel-mongodb authentication
laravel-mongodb query
laravel mongodb rest api
laravel-mongodb raw
laravel-mongodb wherein
laravel-mongodb exists
install jenssegers/laravel-mongodb

First I've set the default by setting the database connection to be mongodb.

'mongodb' => [
      'driver'   => 'mongodb',
      'host'     => 'localhost',
      'username' => 'dofUser',
      'password' => 'dofPass',
      'database' => 'dof',
  ],

Apps/models/user

   <?php
use Jenssegers\Mongodb\Model as Eloquent;

class User extends Eloquent {

    protected $collection = 'user';
    //$user = user::all();
}

and Router

        Route::post('/register', function()
{
   $user->model('User', 'App\Models\User');
   $user = new User;

 $user = User::create(array(
'username' => Input::get('username'),
'fullname' => Input::get('fullname'),
'password' => Hash::make(Input::get('password')),
'gender' => Input::get('gender'),
'month' => Input::get('month'),
'day' => Input::get('day'),
'year' => Input::get('year'),
'phone' => Input::get('phone'),
'email' => Input::get('email-act'),
'agree' => Input::get('agree')
));

    return redirect('/login');

});

But I submit the browser is blank. Not redirect to login in MongoDB I just make a Collection named user.

You don't need to create User again. You can do like this.

 $user = new User();

 $user->'username' = Input::get('username');
 $user->'fullname' = Input::get('fullname');
 $user ->'password' = Hash::make(Input::get('password'));

 $user->save();

 return redirect('/login');

You can check the following tutorial for learn how to insert data to mongodb using Laravel.

Laravel with MongoDB CURD operations - Configuration

Laravel with MongoDB CURD operations - Save data

Check your login routes return something. Please post your method related to the login route.

How to insert MongoDB Document using Laravel, DB::connection('mongodb')->collection('accounts')->insert($insRow);. In my I have set up a fresh new laravel to test mongodb as a second db. To insert a single document using MongoDB Compass: Navigate to the collection you wish to insert the document into: In the left-hand MongoDB Compass navigation pane, click the database to which your target collection belongs. From the database view, click the target collection name.

you can check this tutorial in youtube https://www.youtube.com/watch?v=ltFSEUCCD_4

it teach how to add data into laravel by mongodb

How to insert data into MongoDB with Laravel, #How To Use Laravel With MongoDB​​ Step 3: Install and configure the MongoDB package for Laravel. Step 4: Create a model, route, controller, and view file. Step 5: From the view file, fill the input details and send the POST request to the Laravel server, which then saves the data into MongoDB database. How to insert an object into MongoDB document using Laravel 4 Tag: php , node.js , mongodb , laravel , laravel-4 I am a newbie in Laravel MongoDB I would like to mention a problem here, outline of my Mongo document should be like

Please recheck "return redirect('/login');"

How to insert data on Mongodb, This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. This library extends the original Laravel  In this example we are going to show you how to insert data in database using laravel framework PHP. For insert data in MySQL using laravel first we have to create a table in data base. The INSERT INTO statement is used to insert new data to a MySQL table:

Laravel MongoDB CRUD Example, The documents stored in MongoDB are JSON-like. All data stored in the collection are in BSON format. Switch to a MongoDB database. Here, our  Add Data to MongoDB¶. Overview¶. The code snippets on this page demonstrate how to insert one or more documents into a MongoDB collection. Insert operations take the documents to add to MongoDB as an argument and return documents that describe the results of the operation.

How to set data type in model before insert to mongodb? · Issue , In this Laravel MongoDB Tutorial, You will learn how to fetch records, insert, edit In this step, I will create a "CategoryController.php" file to perform crud action. Laravel 5 tutorial, How To Insert Data in Database complete example of insert data into mysql database with php laravel 5 framework. you can also fine all code for copy and paste from our blog

jenssegers/laravel-mongodb: A MongoDB based Eloquent , A MongoDB based Eloquent model and Query builder for Laravel (Moloquent) for the MongoDB model by adding the following to the alias array in config/app.​php : If you want to use MongoDB to handle failed jobs, change the database in  To import data into a MongoDB instance running on a different host or port, specify the hostname or port by including the --host and --port options. Use the --drop option to drop the collection if it already exists. This ensures that the collection will only contain the data you are importing.

Comments
  • I don't believe that you need to use both $user = new User; and $user = User::create(array(.... The latter is a facade. Also, did you set either a fillable or guarded attribute on the model, "as all Eloquent models protect against mass-assignment." link
  • I do not know, it should be how?
  • class User extends Eloquent { protected $fillable = array('username','fullname'....);
  • The Router how? Sorry I am a novice--I use laravel 5
  • You wrote "But I submit the browser is blank." can you look in storage/logs/ to see if there are relevant errors?