0

I'm getting an error on the following on:

 $user->email    = Input::get('email');

I'm really unsure what is wrong with the code, it seems perfectly fine. I looked up t variable errors, simply involve missing a bracket or semi colon. But as far as I'm aware it seems fine.

If anyone could help me out, that would be great.

If there is any other code, could you list it as a comment and i'll happily add it.

Thanks!

public function doRegister()
{
    $rules = array(
        'name'    => 'required|min:3', // name
        'email'    => 'required|email', // make sure the email is an actual email
        'password' => 'required|alphaNum|min:3' // password can only be alphanumeric and has to be greater than 3 characters
    );

    // run the validation rules on the inputs from the form
    $validator = Validator::make(Input::all(), $rules);

    if ($validator->fails()){
        // validation not successful, send back to form 
        Redirect::back()->withErrors;
    } else {        
        $user = Input::all();
        User::addNewUser();     
        if (Auth::attempt($user)) {
            return Redirect::to('member');
        }
    }

}

User model

    public static function addNewUser()
{
            $user = new User;
            $user->name     = Input::get('name');
            $user->email    = Input::get('email');
            $user->password = Hash::make(Input::get('password'));
            $user->save();
}
0

1 Answer 1

2

It's because of $user->save; it's a method not a property and it should be called like

$user->save();

Instead of

$user->save;

Update : Also, it's U not u

$user = new user;

should be

$user = new User; // capital U

Also, after if ($validator->fails())

Redirect::back()->withErrors;

should be

return Redirect::back()->withErrors($validator);

Update : So, after fixing 3 errors (so far), your full code should be

public function doRegister()
{
    $rules = array(
        'name'    => 'required|min:3',
        'email'    => 'required|email',
        'password' => 'required|alphaNum|min:3'
    );

    $validator = Validator::make(Input::all(), $rules);

    if ($validator->fails()){
        return Redirect::back()->withErrors($validator);
    }
    else {        
        $user = new User;
        $user->name =Input::get('name');
        $user->email= Input::get('email');
        $user->password = Hash::make(Input::get('password'));
        $user->save();

        if (Auth::attempt($user)) {
            return Redirect::to('member');
        }
    }
}
Sign up to request clarification or add additional context in comments.

7 Comments

Hi thank you for the correction, you are right. I still the receive the same error still. Which is rather confusing, here's a screencap of the error if it helps. grab.by/sj0M
thanks for the quick reply, oddly still returns the same error after making the appropriate updates. grab.by/sj18 , unsure where this error must be coming from.
Can you post the full image from the top side with more error details ?
hm I didn't realise there were so many issues with the code I have written. Even with these corrections, the same errors occurs. I'd screencap the error, but it's exactly the same as the previous screen.
1. A screen grab of the entire screen shows lots of other information, including the stack trace. 2. Make sure you're editing the correct file that the error is in, and are uploading it to the appropriate place if not working locally.
|

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.