当前位置: 动力学知识库 > 问答 > 编程问答 >

php - user->save() is not creating a new record in Laravel

问题描述:

I am trying to save details of a user after saving the values in a form. I have written a controller to post the user details and save it in the database, but the user->save() seems to be not working for me.

public function postAddBusiness()

{

$rules = array(

'email' => 'required|email',

'password' => 'same:password_confirm',

'name' => 'required',

'business-type' => 'required'

);

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

if ($validation->fails())

{

return Redirect::to('business/add')->withErrors($validation)->withInput();

}

$user = new User;

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

if (Input::get('password'))

{

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

}

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

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

//$he= $user->save();

if ($user->save())

{

return Redirect::to('dashboard')->with('notify','Information updated');

}

print_r($user);

}

While I return the array $user, I am getting the values I entered in the form.

User Object ( [connection:protected] => [table:protected] => [primaryKey:protected] => id [perPage:protected] => 15 [incrementing] => 1 [timestamps] => 1 [attributes:protected] => Array ( [email] => [email protected] [password] => $2y$10$KWGRMooHxavSbnhcGKqnNe19hstF44lPjVkseX5BwJ.HYUzRzzg7m [name] => B1 [type] => plumber ) [original:protected] => Array ( ) [relations:protected] => Array ( ) [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [appends:protected] => Array ( ) [fillable:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) [dates:protected] => Array ( ) [touches:protected] => Array ( ) [observables:protected] => Array ( ) [with:protected] => Array ( ) [morphClass:protected] => [exists] => [errors] => Illuminate\Support\MessageBag Object ( [messages:protected] => Array ( [username] => Array ( [0] => The username field is required. ) [password_confirmation] => Array ( [0] => Wrong confirmation code. ) ) [format:protected] => :message ) )

Where am I going wrong?

分享给朋友:
您可能感兴趣的文章:
随机阅读: