php - Laravel 4.2 does not save data to the database -
i have problem, don't know i'm messing laravel not save data database , not display errors. here code:
user.php
use illuminate\auth\usertrait; use illuminate\auth\userinterface; use illuminate\auth\reminders\remindabletrait; use illuminate\auth\reminders\remindableinterface; class user extends eloquent implements userinterface, remindableinterface { use usertrait, remindabletrait; /** * database table used model. * * @var string */ protected $table = 'users'; protected $fillable = array('first_name', 'last_name', 'username', 'email', 'password', 'password_temp', 'code', 'active'); /** * attributes excluded model's json form. * * @var array */ protected $hidden = array('password', 'remember_token');
}
routes.php
route::get('/', array( 'as' => 'home', 'uses' => 'pagescontroller@home' )); //unauthenticated group route::group(array('before'=>'guest' ), function(){ //csrf authentication route::group(array('before' => 'csrf'), function(){ //create account (post) route::post('/account/create', array( 'as' => 'account-create', 'uses' => 'accountcontroller@postcreate' )); }); //create account route::get('/account/create', array( 'as' => 'account-create', 'uses' => 'accountcontroller@getcreate' )); });
account.php //here controller used create accounts
class accountcontroller extends basecontroller{ public function getcreate(){ return view::make('account.create'); } public function postcreate(){ $validator = validator::make(input::all(), array( 'first_name' => 'required', 'last_name' => 'required', 'username' => 'required|max:20|min:3|unique:users', 'email' => 'required|max:50|email|unique:users', 'password' => 'required|min:6', 'passsword-repeat' => 'required|same:password' ) ); if($validator->passes()){ //activation code $code = str_random(60); $user = new user; //create account $user->first_name = input::get('first_name'); $user->last_name = input::get('last_name'); $user->username = input::get('username'); $user->email = input::get('email'); $user->password = hash::make(input::get('password')); $user->code = $code; $user->active = 0; $user->save(); //send email of activation return redirect::to('home') ->with('global', 'your account has been created! have sent email activate account'); }else{ return redirect::to('account/create') ->witherrors($validator) ->withinput(); } } }
here view have used: create.blade.php
@extends('master') @section('content') <div class="panel panel-default"> <div class="panel-heading">please register</div> <div class="panel-body"> <div class="col-md-4 col-md-offset-4"> {{ form::open(array('route' => 'account-create', 'class' => 'form-horizontal', 'method' => 'post'))}} <fieldset> <div class="control-group"> {{ form::label('first_name', 'first name', array('class' => 'control-label') )}} <div class="controls"> {{ form::text('first_name', input::old('first_name'), array('class' => 'form-control input-medium', 'placeholder' => 'enter first name') )}} <p class="error">{{ $errors->first('first_name')}}</p> </div> </div> <div class="control-group"> {{ form::label('last_name', 'last name', array('class' => 'control-label') )}} <div class="controls"> {{ form::text('last_name', input::old('last_name'), array('class' => 'form-control input-medium', 'placeholder' => 'enter last name') )}} <p class="error">{{ $errors->first('last_name')}}</p> </div> </div> <div class="control-group"> {{ form::label('username', 'username', array('class' => 'control-label') )}} <div class="controls"> {{ form::text('username',input::old('username'), array('class' => 'form-control input-medium', 'placeholder' => 'enter username') )}} <p class="error">{{ $errors->first('username')}}</p> </div> </div> <div class="control-group"> {{ form::label('email', 'email', array('class' => 'control-label') )}} <div class="controls"> {{ form::text('email', input::old('email') , array('class' => 'form-control input-medium', 'placeholder' => 'enter email') )}} <p class="error">{{ $errors->first('email')}}</p> </div> </div> <!-- password input--> <div class="control-group"> {{ form::label('password', 'password', array('class' => 'control-label') )}} <div class="controls"> {{ form::password('password', array('class' => 'form-control')) }} <p class="error">{{ $errors->first('password')}}</p> </div> </div> <div class="control-group"> {{ form::label('password-repeat', 're-enter password', array('class' => 'control-label') )}} <div class="controls"> {{ form::password('password-repeat', array('class' => 'form-control')) }} <p class="error">{{ $errors->first('password-repeat')}}</p> </div> </div> <!-- button --> <div class="control-group"> <div class="controls"> {{form::submit('sign up', ['class' => 'btn btn-large btn-primary', 'id'=> 'signup'])}} </div> </div> </fieldset> {{ form::close() }} </div> </div> </div>
@stop
it validates whenever want create user , save data database nothing happening , returns same login page data tried save without error message . please me if can spot mistake
Comments
Post a Comment