1

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.

6
  • 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 Commented Mar 21, 2015 at 8:48
  • I do not know, it should be how? Commented Mar 21, 2015 at 8:51
  • class User extends Eloquent { protected $fillable = array('username','fullname'....); Commented Mar 21, 2015 at 8:52
  • The Router how? Sorry I am a novice--I use laravel 5 Commented Mar 21, 2015 at 8:56
  • You wrote "But I submit the browser is blank." can you look in storage/logs/ to see if there are relevant errors? Commented Mar 21, 2015 at 9:11

3 Answers 3

1

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.

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

Comments

0

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

Comments

0

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

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.